Skip to content

Commit d2c01fe

Browse files
authored
Create 1560-most-visited-sector-in-a-circular-track.js
1 parent 3aff380 commit d2c01fe

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {number} n
3+
* @param {number[]} rounds
4+
* @return {number[]}
5+
*/
6+
const mostVisited = function(n, rounds) {
7+
const arr = Array(n + 1).fill(0)
8+
for(let i = 1, m = rounds.length; i < m; i++) {
9+
let start = rounds[i - 1], end = rounds[i]
10+
11+
if(i == 1) arr[start]++
12+
while(start !== end) {
13+
start += 1
14+
if (start === n + 1) start = 1
15+
arr[start]++
16+
}
17+
}
18+
const max = Math.max(...arr)
19+
const res = []
20+
for(let i = 1; i <= n; i++) {
21+
if(arr[i] === max) res.push(i)
22+
}
23+
return res
24+
};

0 commit comments

Comments
 (0)