File tree 2 files changed +50
-1
lines changed
2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,368 LeetCode solutions in JavaScript
1
+ # 1,369 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1191
1191
1557|[ Minimum Number of Vertices to Reach All Nodes] ( ./solutions/1557-minimum-number-of-vertices-to-reach-all-nodes.js ) |Medium|
1192
1192
1558|[ Minimum Numbers of Function Calls to Make Target Array] ( ./solutions/1558-minimum-numbers-of-function-calls-to-make-target-array.js ) |Medium|
1193
1193
1559|[ Detect Cycles in 2D Grid] ( ./solutions/1559-detect-cycles-in-2d-grid.js ) |Medium|
1194
+ 1560|[ Most Visited Sector in a Circular Track] ( ./solutions/1560-most-visited-sector-in-a-circular-track.js ) |Easy|
1194
1195
1566|[ Detect Pattern of Length M Repeated K or More Times] ( ./solutions/1566-detect-pattern-of-length-m-repeated-k-or-more-times.js ) |Easy|
1195
1196
1576|[ Replace All ?'s to Avoid Consecutive Repeating Characters] ( ./solutions/1576-replace-all-s-to-avoid-consecutive-repeating-characters.js ) |Medium|
1196
1197
1598|[ Crawler Log Folder] ( ./solutions/1598-crawler-log-folder.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1560. Most Visited Sector in a Circular Track
3
+ * https://leetcode.com/problems/most-visited-sector-in-a-circular-track/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an integer n and an integer array rounds. We have a circular track which consists of n
7
+ * sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of
8
+ * m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For
9
+ * example, round 1 starts at sector rounds[0] and ends at sector rounds[1]
10
+ *
11
+ * Return an array of the most visited sectors sorted in ascending order.
12
+ *
13
+ * Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise
14
+ * direction (See the first example).
15
+ */
16
+
17
+ /**
18
+ * @param {number } n
19
+ * @param {number[] } rounds
20
+ * @return {number[] }
21
+ */
22
+ var mostVisited = function ( n , rounds ) {
23
+ const sectorVisits = new Array ( n + 1 ) . fill ( 0 ) ;
24
+ let maxVisits = 0 ;
25
+
26
+ for ( let i = 1 ; i < rounds . length ; i ++ ) {
27
+ let start = rounds [ i - 1 ] ;
28
+ const end = rounds [ i ] ;
29
+
30
+ while ( start !== end ) {
31
+ sectorVisits [ start ] ++ ;
32
+ maxVisits = Math . max ( maxVisits , sectorVisits [ start ] ) ;
33
+ start = start === n ? 1 : start + 1 ;
34
+ }
35
+ }
36
+
37
+ sectorVisits [ rounds [ rounds . length - 1 ] ] ++ ;
38
+ maxVisits = Math . max ( maxVisits , sectorVisits [ rounds [ rounds . length - 1 ] ] ) ;
39
+
40
+ const result = [ ] ;
41
+ for ( let i = 1 ; i <= n ; i ++ ) {
42
+ if ( sectorVisits [ i ] === maxVisits ) {
43
+ result . push ( i ) ;
44
+ }
45
+ }
46
+
47
+ return result ;
48
+ } ;
You can’t perform that action at this time.
0 commit comments