Skip to content

Commit f9264d6

Browse files
authored
Create most-visited-sector-in-a-circular-track.cpp
1 parent f7cc251 commit f9264d6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
vector<int> mostVisited(int n, vector<int>& rounds) {
7+
vector<int> result;
8+
if (rounds.front() <= rounds.back()) {
9+
for (int i = rounds.front(); i <= rounds.back(); ++i) {
10+
result.emplace_back(i);
11+
}
12+
} else {
13+
for (int i = 1; i <= rounds.back(); ++i) {
14+
result.emplace_back(i);
15+
}
16+
for (int i = rounds.front(); i <= n; ++i) {
17+
result.emplace_back(i);
18+
}
19+
}
20+
return result;
21+
}
22+
};

0 commit comments

Comments
 (0)