Algorithm
-
[LeetCode] 19. Remove Nth Node From End of List 문제풀이Algorithm/문제풀이 2021. 9. 3. 21:37
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 문제 내용 List의 끝에서 n번째 element를 제거하는 문제 근데 one pass 만에 하라고 한다. 문제 풀이 size를 구해서 size - n하면 제거할 node를 찾아서 했다. class Solution { public: ListN..
-
[LeetCode] 876. Middle of the Linked List 문제 풀이Algorithm/문제풀이 2021. 9. 3. 20:20
https://leetcode.com/problems/middle-of-the-linked-list/ Middle of the Linked 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 문제 내용 List 에서 중간 노드를 찾는 문제 문제 풀이 전체 리스트의 크기만 알면 그 절반을 구할 수 있다. class Solution { public: ListNode* middleNode(ListNode* head) { int size = 0; ListNode..
-
[LeetCode] 95. Unique Binary Search Trees II 문제 풀이Algorithm/문제풀이 2021. 9. 3. 01:57
https://leetcode.com/problems/unique-binary-search-trees-ii/ Unique Binary Search Trees II - 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 문제 내용 정수 n 이 주어질 때, [1, n] 의 node에서 binary search tree 로 구성할 수 있는 배열을 출력 Example 1: Input: n = 3 Output: [[1,null,2,null,3],[1,null,3,2],[2,1..
-
[LeetCode] 153. Find Minimum in Rotated Sorted Array 문제풀이Algorithm/문제풀이 2021. 9. 1. 21:25
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Find Minimum in Rotated Sorted Array - 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 문제 내용 정렬된 배열에 로테이션된 상황이 주어졌을 때, 최소값을 찾는 문제 Example 1: Input: nums = [3,4,5,1,2] Output: 1 Explanation: The original array was [..
-
[LeetCode] 167. Two Sum II - Input array is sorted 문제풀이Algorithm/문제풀이 2021. 9. 1. 20:13
https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input array is sorted - 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 문제 내용 정렬되어 있는 배열에서 2개의 합이 target이랑 일치할 때 배열의 index 2개를 출력 문제 풀이 두 숫자의 합을 구하는 것을 target을 뺀 다음에 바이너리 서치로 찾는 방법을 생각했다. class Solution { ..
-
[LeetCode] 283. Move Zeroes 문제풀이Algorithm/문제풀이 2021. 9. 1. 18:59
https://leetcode.com/problems/move-zeroes/ Move Zeroes - 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 문제 내용 배열에 0값이 섞여있는데 정렬상태를 유지하면서 0을 end쪽으로 몰아 넣는 문제 문제 풀이 index 2개로 swap하면 됐다. class Solution { public: void moveZeroes(vector& nums) { for (int i = 0, j = 0; i < nums.size(); ++..
-
[LeetCode] 977. Squares of a Sorted Array 문제풀이Algorithm/문제풀이 2021. 9. 1. 10:54
https://leetcode.com/problems/squares-of-a-sorted-array/ Squares of a Sorted Array - 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 문제 내용 오름차순으로 정렬되어 있는 배열을 제곱근한 값으로 정렬하는 것 Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array become..
-
[LeetCode] Longest Uncommon Subsequence II 문제풀이Algorithm/문제풀이 2021. 8. 28. 14:01
https://leetcode.com/problems/longest-uncommon-subsequence-ii/ Longest Uncommon Subsequence II - 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 문제 내용 문자열 배열 중에 LCS가 하나도 없는 문자열 길이 중 최대 값 찾기 문제 풀이 Trie 이용해서 매칭으로 푸는 방법 문자열 부분 집합중에 공통된 것이 없으면 된다고 생각했다. 문자열에 대해 부분 집합을 모두 구하고, 문자열 매칭 자료..