1752. Check if Array Is Sorted and Rotated
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 55% Topics: Array
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def check(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
count = 0
for i in xrange(len(nums)):
if nums[i] > nums[(i+1)%len(nums)]:
count += 1
if count > 1:
return False
return True
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions