일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Array
- Binary
- easy
- Medium
- DP
- 문자열
- binary tree
- leetcode
- hash table
- 중간
- two pointers
- backtracking
- recursive
- dfs
- 쉬움
- linked list
- matrix
- math
- binary search
- sorting
- 미디움
- string
- 리트코드
- 이진트리
- Depth-first Search
- Python
- 재귀
- list
- tree
- HashTable
- Today
- Total
목록linked list (12)
부부의 코딩 성장 일기
1. 문제 링크 https://leetcode.com/problems/reorder-list/ 2. 문제 설명 linked list의 head가 주어졌을 때, 해당 list를 아래처럼 표현할 수 있다. L0 → L1 → ... → Ln-1 → Ln 이 때, 아래의 형태가 되도록 list를 reorder해라. L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → ... 여기서 node의 value자체를 수정하는 것이 아니라, node의 연결관계를 바꿔야 한다. 예시1) head가 [1,2,3,4]로 1→2→3→4의 연결관계를 가지고 있다면, 1→4→2→3으로 변경할 수 있다. output = [1,4,2,3] 예시2) head가 [1,2,3,4,5]로 1→2→3→4→5의 연결관계를 가지고 있다면, ..
1. 문제 링크 https://leetcode.com/problems/linked-list-cycle-ii/description/ 2. 문제 설명 연결 리스트(Linked List)에서 순환(사이클)이 발생하는 경우, 순환의 시작 지점 노드를 반환하고, 사이클이 없으면 None 반환 3. 처음 풀이 노드를 한 칸씩 전진하며 set에 저장하고, 이미 들어있으면 그 노드를 반환. 끝까지 갈 동안 같은 노드가 나오지 않으면 사이클이 없으므로 return None 공간 복잡도 O(n)으로 좋지 않다. # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class..

1. 문제 링크 https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 2. 문제 설명 아래 형태의 binary tree가 주어졌을 때 struct Node { int val; Node *left; Node ..
1. 문제 링크 https://leetcode.com/problems/reverse-linked-list-ii/ Reverse Linked List II - LeetCode Can you solve this real interview question? Reverse Linked List II - Given the head of a singly linked list and two integers left and right where left Optional[ListNode]: # 예외 처리: 노드가 없거나 하나뿐이면 원래 리스트 반환 if not head or not head.next: return head # 예외 처리: 노드가 두 개일 때 if not head.next.next: # left와 righ..
1. 문제 링크 https://leetcode.com/problems/reverse-linked-list/description/ Reverse Linked List - LeetCode Can you solve this real interview question? Reverse Linked List - Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: [https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg] Input: head = [1,2,3,4,5] O leetcode.com 2. 문제 설명 linked list인 head가 ..
1. 문제 링크 https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/description/ Partition List - LeetCode Can you solve this real interview question? Partition List - Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the no leetcode.com 2. 문제 설명 정렬된..
1. 문제 링크 https://leetcode.com/problems/rotate-list/ Rotate List - LeetCode Can you solve this real interview question? Rotate List - Given the head of a linked list, rotate the list to the right by k places. Example 1: [https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg] Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1 leetcode.com 2. 문제 설명 linked list의 head가 주어졌을 때, k번 오른쪽으로 회전한 linked l..
1. 문제 링크 Swap Nodes in Pairs - LeetCode Swap Nodes in Pairs - LeetCode Can you solve this real interview question? Swap Nodes in Pairs - Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be chan leetcode.com 2. 문제 설명 주어진 연결 리스트의 인접한 두 (홀수, 짝수) 노드를 서로 바꾸어 (짝수, 홀수)로 반환..