Skip to content

Commit 69bcea2

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 43.10 MB (Top 12.5%)
1 parent a380d2e commit 69bcea2

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 43.10 MB (Top 12.5%)
2+
13
class Solution {
24
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);
1313
}
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;
2615
}
2716
}

0 commit comments

Comments
 (0)