Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]
Return an array of the most visited sectors sorted in ascending order.
Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).
Example 1:
1 | Input: n = 4, rounds = [1,3,1,2] |
Example 2:
1 | Input: n = 2, rounds = [2,1,2,1,2,1,2,1,2] |
Example 3:
1 | Input: n = 7, rounds = [1,3,5,7] |
這篇我沒想出來,所以程式是外國網友的,題意是找跑幾圈後經過最多次的扇形區域,一圈分成四塊,一開始給幾個round(跑幾次)跟每次停留的區塊,解題思路是看起終點的扇形區域,起>=終,起到終一定是多的,起>終一定從1過一圈,再加上起點到過了幾圈,學到可以直接把range轉list。
如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)