Skip to content

Commit 7c294e9

Browse files
committed
Added Python solution for "Check if Array Is Sorted and Rotated"
1 parent 97cc25b commit 7c294e9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""
6+
Time: O(n)
7+
Memory: O(1)
8+
"""
9+
10+
def check(self, nums: List[int]) -> bool:
11+
n = len(nums)
12+
13+
for i in range(1, n):
14+
if nums[i - 1] > nums[i]:
15+
return nums[0] >= nums[-1] and all(nums[j] <= nums[j + 1] for j in range(i, n - 1))
16+
17+
return True
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)