일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- shiba
- Convert Sorted List to Binary Search Tree
- data science
- 컴퓨터의 구조
- 43. Multiply Strings
- Python
- 30. Substring with Concatenation of All Words
- Class
- Regular Expression
- attribute
- Python Implementation
- 715. Range Module
- concurrency
- Decorator
- iterator
- 운영체제
- 315. Count of Smaller Numbers After Self
- 파이썬
- Protocol
- DWG
- kaggle
- 프로그래머스
- 밴픽
- 109. Convert Sorted List to Binary Search Tree
- LeetCode
- 시바견
- Generator
- t1
- Python Code
Archives
- Today
- Total
Scribbling
LeetCode: 19. Remove Nth Node From End of List 본문
Computer Science/Coding Test
LeetCode: 19. Remove Nth Node From End of List
focalpoint 2021. 8. 22. 22:44# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
length = 0
cur = head
while cur != None:
length += 1
cur = cur.next
prv, cur = None, head
num_move = length - n
while num_move > 0:
prv = cur
cur = cur.next
num_move -= 1
if cur == head:
return head.next
prv.next = cur.next
return head
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 25. Reverse Nodes in k-Group (0) | 2021.08.25 |
---|---|
LeetCode: 22. Generate Parentheses (0) | 2021.08.24 |
LeetCode: 18. 4Sum (0) | 2021.08.22 |
LeetCode: 17. Letter Combinations of a Phone Number (0) | 2021.08.21 |
LeetCode: 16. 3Sum Closest (0) | 2021.08.21 |