일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- kaggle
- shiba
- attribute
- Protocol
- 시바견
- LeetCode
- iterator
- 프로그래머스
- Convert Sorted List to Binary Search Tree
- 운영체제
- Python
- t1
- 컴퓨터의 구조
- Decorator
- Generator
- concurrency
- Regular Expression
- Python Code
- data science
- 315. Count of Smaller Numbers After Self
- 715. Range Module
- Class
- 43. Multiply Strings
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- Python Implementation
- 30. Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- 파이썬
Archives
- Today
- Total
Scribbling
LeetCode: 61. Rotate List 본문
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def rotateRight(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:
if not head:
return
count, cur, prv = 0, head, None
while cur != None:
prv = cur
count += 1
cur = cur.next
tail = prv
k %= count
if k == 0:
return head
cur = head
for i in range(count - k - 1):
cur = cur.next
new_head = cur.next
cur.next = None
tail.next = head
return new_head
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 63. Unique Paths II (0) | 2021.09.24 |
---|---|
LeetCode: 62. Unique Paths (0) | 2021.09.24 |
LeetCode: 60. Permutation Sequence (0) | 2021.09.24 |
LeetCode: 59. Spiral Matrix II (0) | 2021.09.24 |
LeetCode: 53. Maximum Subarray (0) | 2021.09.24 |