Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Check if Array Is Sorted and Rotated - Python
Views: 309 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class Solution:
    def check(self, nums: List[int]) -> bool:
        if len(nums) == 1:
            return True
        s = min(nums)
        for _ in range(len(nums)):
            if s == nums[0] and nums[-1] != s:
                break
            nums.append(nums.pop(0))
        for i in range(len(nums)):
            if i == 0:
                continue
            if not nums[i-1] <= nums[i]:
                return False
        return True