일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 30. Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- 43. Multiply Strings
- 시바견
- Class
- 715. Range Module
- Substring with Concatenation of All Words
- concurrency
- DWG
- kaggle
- Generator
- Python Code
- Convert Sorted List to Binary Search Tree
- 프로그래머스
- shiba
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- attribute
- Protocol
- 파이썬
- LeetCode
- t1
- 운영체제
- iterator
- Python Implementation
- 컴퓨터의 구조
- Decorator
- data science
- Python
- 밴픽
Archives
- Today
- Total
Scribbling
LeetCode: 86. Partition List 본문
간단하면서도 재밌는 문제
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def partition(self, head: Optional[ListNode], x: int) -> Optional[ListNode]:
smaller_train = ListNode()
s_ptr = smaller_train
bigger_train = ListNode()
b_ptr = bigger_train
cur = head
while cur != None:
if cur.val < x:
s_ptr.next = cur
s_ptr = cur
else:
b_ptr.next = cur
b_ptr = cur
cur = cur.next
b_ptr.next = None
s_ptr.next = bigger_train.next
return smaller_train.next
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 89. Gray Code (0) | 2021.10.08 |
---|---|
LeetCode: 126. Word Ladder II (0) | 2021.10.06 |
LeetCode: 82. Remove Duplicates from Sorted List II (0) | 2021.10.06 |
LeetCode: 81. Search in Rotated Sorted Array II (0) | 2021.10.06 |
LeetCode: 80. Remove Duplicates from Sorted Array II (0) | 2021.10.06 |