File tree 1 file changed +11
-22
lines changed
scripts/algorithms/M/Most Visited Sector in a Circular Track
1 file changed +11
-22
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 0 ms (Top 100.0%) | Memory: 43.10 MB (Top 12.5%)
2
+
1
3
class Solution {
2
4
public List <Integer > mostVisited (int n , int [] rounds ) {
3
- int []psum =new int [n +2 ];
4
- psum [rounds [0 ]]+=1 ;
5
- psum [rounds [1 ]+1 ]-=1 ;
6
- if (rounds [0 ]>rounds [1 ])
7
- psum [1 ]+=1 ;
8
- for (int i =2 ;i <rounds .length ;i ++){
9
- psum [rounds [i -1 ]+1 ]+=1 ;
10
- psum [rounds [i ]+1 ]-=1 ;
11
- if (rounds [i -1 ]>rounds [i ])
12
- psum [1 ]+=1 ;
5
+ var start = rounds [0 ];
6
+ var end = rounds [rounds .length - 1 ];
7
+ var res = new ArrayList <Integer >();
8
+ if (start <= end ) {
9
+ for (int i = start ; i <= end ; i ++) res .add (i );
10
+ } else {
11
+ for (int i = 1 ; i <= end ; i ++) res .add (i );
12
+ for (int i = start ; i <= n ; i ++) res .add (i );
13
13
}
14
- int max_ =0 ;
15
- for (int i =1 ;i <=n ;i ++){
16
- psum [i ]+=psum [i -1 ];
17
- if (psum [i ]>max_ )
18
- max_ =psum [i ];
19
- }
20
- List <Integer >ans =new ArrayList <>();
21
- for (int i =1 ;i <=n ;i ++){
22
- if (psum [i ]==max_ )
23
- ans .add (i );
24
- }
25
- return ans ;
14
+ return res ;
26
15
}
27
16
}
You can’t perform that action at this time.
0 commit comments