일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- DWG
- Regular Expression
- Python Code
- Generator
- 프로그래머스
- 컴퓨터의 구조
- data science
- Class
- concurrency
- Python
- 운영체제
- Convert Sorted List to Binary Search Tree
- 시바견
- LeetCode
- 밴픽
- 파이썬
- Python Implementation
- t1
- attribute
- Protocol
- shiba
- 109. Convert Sorted List to Binary Search Tree
- Substring with Concatenation of All Words
- 30. Substring with Concatenation of All Words
- 715. Range Module
- 43. Multiply Strings
- kaggle
- Decorator
- iterator
- 315. Count of Smaller Numbers After Self
Archives
- Today
- Total
Scribbling
LeetCode: 31. Next Permutation 본문
class Solution:
def nextPermutation(self, nums: List[int]) -> None:
i = len(nums) - 1
while i - 1 >= 0 and nums[i-1] >= nums[i]:
i -= 1
if i == 0:
return nums.sort()
swap_idx, swap_val = None, int(1e9)
for j in range(i, len(nums)):
if nums[j] > nums[i-1] and nums[j] < swap_val:
swap_val = nums[j]
swap_idx = j
nums[i-1], nums[swap_idx] = nums[swap_idx], nums[i-1]
nums[i:] = sorted(nums[i:])
'Computer Science > Coding Test' 카테고리의 다른 글
34. Find First and Last Position of Element in Sorted Array (0) | 2021.09.11 |
---|---|
33. Search in Rotated Sorted Array (0) | 2021.09.11 |
35. Search Insert Position (0) | 2021.09.08 |
LeetCode: 49. Group Anagrams (0) | 2021.09.08 |
LeetCode: 41. First Missing Positive (0) | 2021.09.08 |