본문 바로가기

Leetcode

876. Middle of the Linked List Solution 몇개인지 갯수를 세고, 그 갯수/2 만큼 head를 이동시켜서 return. 더보기
206. Reverse Linked List 주어진 LinkedList 를 Reverse 하는 문제. 복잡한 문제 같지만 천천히 생각해보면 그렇지 않다. 1) 첫번째 직관적인 솔루션 Prev라는 이전 노드를 저장하는 노드를 정의. 1 -> 2 -> 3 이라는 리스트가 있다면, Prev = nullptr 일때, head = 1 Prev = 1 일때, head = 2 Prev = 2 일때, head = 3 Prev = 3 일때, head = nullptr이 된다. 즉 새로운 Prev = head가 되고, 새로운 Prev의 next 는 Prev가 된다. 여기서 나는 tp라는 새로운 노드를 만들었고, tp 는 새로운 Prev 노드인데 이는, head->val의 값을 갖고 현재 prev를 next에 저장한다. 그리고 head 를 이동시켜준다. 이는 새로운 .. 더보기
392. Is Subsequence 이건 정말 설명할게 없어서, t 문자열을 스캔할 때, s 문자열에 대한 포인터를 유지하면서, 일치하는게 있으면 p ++ 아니면 t 문자열 인덱스로 넘어간다. 총 p의 갯수가 s 문자열의 길이와 같으면 subsequence 가 true 아니면 false 더보기
724. Find Pivot Index Input: nums = [1,7,3,6,5,6] Output: 3 Explanation: The pivot index is 3. Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11 Right sum = nums[4] + nums[5] = 5 + 6 = 11 Input: nums = [1,2,3] Output: -1 Explanation: There is no index that satisfies the conditions in the problem statement. Input: nums = [2,1,-1] Output: 0 Explanation: The pivot index is 0. Left sum = 0 (no elements to the left .. 더보기
LeetCode 75 Challenge https://leetcode.com/study-plan/leetcode-75/?progress=xo5m1ux2 LeetCode 75 - Study Plan - LeetCode This study plan is for those who want to prepare for technical interviews but are uncertain which problems they should focus on. The problems have been carefully curated so that levels 1 and 2 will guide beginner and intermediate users through problems tha leetcode.com Leet code 75 challenge를 시작한다 .. 더보기