일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- Python
- Class
- Substring with Concatenation of All Words
- DWG
- Generator
- data science
- Protocol
- 315. Count of Smaller Numbers After Self
- kaggle
- LeetCode
- 프로그래머스
- 밴픽
- Python Implementation
- 컴퓨터의 구조
- 파이썬
- iterator
- 30. Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- 43. Multiply Strings
- Python Code
- t1
- attribute
- shiba
- concurrency
- 시바견
- Decorator
- 운영체제
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 |