Leetcode 1878 Solution
This article provides solution to leetcode question 1878 (check-if-array-is-sorted-and-rotated)
Access this page by simply typing in "lcs 1878" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/check-if-array-is-sorted-and-rotated
Solution
class Solution:
def check(self, nums: List[int]) -> bool:
if len(nums) == 1:
return True
state = 0
for i in range(1, len(nums)):
if nums[i - 1] > nums[i]:
if state == 1:
return False
else:
state = 1
if state == 0:
return True
else:
return nums[0] >= nums[-1]