Linked list
-
[LeetCode] Remove Nth Node From End of List카테고리 없음 2019. 9. 21. 21:48
문제 Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. Approach 끝에서 부터 n번째이기 때문에 조금 신경을 써야한다. vector를 만들고 node를 읽을 때 하나씩 벡터에 push_back해서 모든 노드를 저장한 다음, 전부 읽은 뒤에서 n+1번째랑 n-1를 이어주면 끝 n이 전체 list 길이일..
-
[LeetCode] Merge Two Sorted List알고리즘 2019. 9. 21. 01:49
문제 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 Approach https://noname122.tistory.com/9?category=851290 [LeetCode] Median of Two Sorted Array 문제 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ..