일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 3줄정리
- 스탭퍼
- 개발자
- 쓰릴오브파이트
- 파비최
- 운동
- 리얼 클래스
- leetcode
- 링피트
- Problem Solving
- 읽기
- English
- 30분
- 월간
- 잡생각
- 영어원서읽기
- 프로젝트
- realclass
- FIT XR
- Daily Challenge
- 미드시청
- 뭐든
- 10분
- 매일
- Writing
- 영어공부
- 화상영어
- 만화도
- 사이드
- 괜찮음
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.05.15 Today's Challenge 본문
https://leetcode.com/problems/swapping-nodes-in-a-linked-list/
Swapping Nodes in a Linked List - LeetCode
Can you solve this real interview question? Swapping Nodes in a Linked List - You are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from t
leetcode.com
이제 DP는 끝나고 링크드 리스트 문제들이 나올 예정인가 보다
class Solution:
def swapNodes(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:
l_node = head
for i in range(1, k):
l_node = l_node.next
r_node = head
cur_node = l_node
while cur_node.next:
cur_node = cur_node.next
r_node = r_node.next
l_node.val, r_node.val = r_node.val, l_node.val
return head
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.05.17 Today's Challenge (0) | 2023.05.17 |
---|---|
2023.05.16 Today's Challenge (0) | 2023.05.16 |
2023.05.14 Today's Challenge (0) | 2023.05.14 |
2023.05.13 Today's Challenge (1) | 2023.05.13 |
2023.05.12 Today's Challenge (0) | 2023.05.12 |
Comments