일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 315. Count of Smaller Numbers After Self
- 파이썬
- attribute
- 시바견
- data science
- Generator
- 운영체제
- iterator
- Python Code
- Substring with Concatenation of All Words
- 프로그래머스
- LeetCode
- Regular Expression
- 715. Range Module
- shiba
- Python
- Convert Sorted List to Binary Search Tree
- concurrency
- t1
- 컴퓨터의 구조
- 43. Multiply Strings
- Class
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- Decorator
- 밴픽
- 30. Substring with Concatenation of All Words
- Protocol
- DWG
- kaggle
Archives
- Today
- Total
Scribbling
LeetCode: 82. Remove Duplicates from Sorted List II 본문
Computer Science/Coding Test
LeetCode: 82. Remove Duplicates from Sorted List II
focalpoint 2021. 10. 6. 16:09# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
if not head:
return None
new_head = ListNode()
ptr = new_head
reg, freq = head.val, 0
cur = head
while cur != None:
if reg != cur.val:
if freq == 1:
temp = ListNode(reg)
ptr.next = temp
ptr = temp
reg = cur.val
freq = 1
else:
freq += 1
cur = cur.next
if freq == 1:
ptr.next = ListNode(reg)
return new_head.next
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 126. Word Ladder II (0) | 2021.10.06 |
---|---|
LeetCode: 86. Partition List (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 |
LeetCode: 84. Largest Rectangle in Histogram (0) | 2021.10.04 |