From 369fb6e0de12b8f609da1f0a2602ba453f7cc876 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Sun, 2 Feb 2025 20:41:43 +0900 Subject: [PATCH] https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/ --- easy/check_if_array_is_sorted_and_rotated.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 easy/check_if_array_is_sorted_and_rotated.py diff --git a/easy/check_if_array_is_sorted_and_rotated.py b/easy/check_if_array_is_sorted_and_rotated.py new file mode 100644 index 0000000..5c97800 --- /dev/null +++ b/easy/check_if_array_is_sorted_and_rotated.py @@ -0,0 +1,13 @@ +# https://leetcode.com/problems/check-if-array-is-sorted-and-rotated + +from typing import List + +class Solution: + def check(self, nums: List[int]) -> bool: + if len(nums) == 1: + return True + cnt = 0 + for i in range(len(nums)): + if nums[i - 1] > nums[i]: + cnt += 1 + return cnt <= 1