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