일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Substring with Concatenation of All Words
- 시바견
- 밴픽
- concurrency
- kaggle
- 운영체제
- Regular Expression
- Class
- Generator
- t1
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 30. Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- 715. Range Module
- iterator
- attribute
- LeetCode
- Decorator
- Python Code
- Python Implementation
- 컴퓨터의 구조
- shiba
- 파이썬
- Python
- DWG
- 43. Multiply Strings
- Protocol
- data science
- 프로그래머스
Archives
- Today
- Total
Scribbling
LeetCode: 92. Reverse Linked List II 본문
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]:
new_head = ListNode(val=0, next=head)
count = 0
ptr = new_head
prev, cur = None, new_head
nxt = head
for i in range(left):
prev = cur
cur = nxt
nxt = cur.next
cut_tail = prev
reversed_head = cur
for i in range(right-left):
prev = cur
cur = nxt
nxt = cur.next
cur.next = prev
reversed_tail = cur
cut_head = nxt
cut_tail.next = reversed_tail
reversed_head.next = cut_head
return new_head.next
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 96. Unique Binary Search Trees (0) | 2021.10.13 |
---|---|
LeetCode: 95. Unique Binary Search Trees II (0) | 2021.10.13 |
LeetCode: 97. Interleaving String (0) | 2021.10.11 |
LeetCode: 93. Restore IP Addresses (0) | 2021.10.11 |
LeetCode: 91. Decode Ways (0) | 2021.10.11 |