Post

leetcode(리트코드)-1752 Check if Array Is Sorted and Rotated(PYTHON)

leetcode 1752 - Check if Array Is Sorted and Rotated 문제입니다.

1. 문제

https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/


2. Input , Output


3. 분류 및 난이도

Eazy 난이도 문제입니다.


4. 문제 해석

  • nums가 주어집니다.
  • nums를 회전했을 때 오름차순으로 정렬되어 있으면 True를 회전을 아무리 해도 오름차순으로 정렬될 수 없다면 False를 리턴합니다.

5. code

python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
    def check(self, nums: List[int]) -> bool:
        temp = nums[:]
        temp.sort()
        nums = deque(nums)
        temp = deque(temp)
        for i in range(len(nums)):
            if temp == nums:
                return True
            else:
                shift = nums.popleft()
                nums.append(shift)
            
        return False
            

6. 결과 및 후기, 개선점

필요시 c++로 짜드립니다.

설명이 필요하다면 댓글을 달아주세요.

This post is licensed under CC BY 4.0 by the author.