일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 영어공부
- 개발자
- 읽기
- 쓰릴오브파이트
- Writing
- 잡생각
- 파비최
- 뭐든
- Daily Challenge
- 운동
- Problem Solving
- 만화도
- FIT XR
- 10분
- 스탭퍼
- leetcode
- 프로젝트
- 매일
- realclass
- 미드시청
- 3줄정리
- 영어원서읽기
- English
- 리얼 클래스
- 링피트
- 화상영어
- 월간
- 30분
- 괜찮음
- 사이드
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/remove-nth-node-from-end-of-list/
Remove Nth Node From End of List - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
개념 자체는 간단쓰.
리스트를 순회하면서 크기를 일단 구하고 삭제할 노드를 제거 한 뒤 이어 붙이면 된다.
근데 구현은 쪼깨 힘드네 =_=
class Solution:
def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
l = 0
h = head
while h:
h = h.next
l += 1
c = l - n + 1
if n == l:
return head.next
cnt = 1
pre = None
curr = head
while curr:
if cnt == c:
pre.next = curr.next
break
cnt += 1
pre = curr
curr = curr.next
return head
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.09.30 |
---|---|
Today's Challenge (0) | 2022.09.29 |
Today's Challenge (0) | 2022.09.27 |
Today's Challenge (0) | 2022.09.25 |
Today's Challenge (0) | 2022.09.24 |
Comments