5495. 圆形赛道上经过次数最多的扇区 LeetCode第 204 场周赛

5495. 圆形赛道上经过次数最多的扇区 LeetCode第 204 场周赛

传送门

传送门

结题思路

# 思路1:
# 无论怎么跑,从起点开始跑,到终点的路程是经过次数最多的。所以中间的情况可以忽略。
# 分两种情况:
# 若终点大于等于起点,则起点到终点的这一段经过次数最多;
# 若终点小于起点,起点到n,然后n到终点的这一段经过的次数最多。
class Solution(object):
    def mostVisited(self, n, rounds):
        """
        :type n: int
        :type rounds: List[int]
        :rtype: List[int]
        """
        start, end = rounds[0], rounds[-1]
        if(start < end):
            return [i for i in range(start, end+1)]
        elif start > end:
            return [i for i in range(1, end+1)] + [i for i in range(start, n+1)]
        else:
            return [start]

猜你喜欢

转载自blog.csdn.net/qq_40092110/article/details/108184864