본문 바로가기

릿코드

205. Isomorphic Strings 이 문제는 딱히 고민할게 없는 전형적인 해시테이블을 이용한 문제이지만, 그래도 생각해볼 것을 몇 가지 적어보았다. Runtime : 22 ms 일단 나는 map과 set을 이용해서 문제를 풀었다. 왼쪽부터 스캔하면서, 첫번째 if statement : "maplist" 에서 key(알파벳)을 발견할 수 있었는가? 같은 value를 가지고 있는가? 아니라면 False 두번째 if statement : "maplist" 에 key 값이 없다면, 동일한 value 를 가진 key가 존재하는가? * visited.insert('key').second 는 중복되는 값이 없었다면 True를, 아니라면 False를 반환한다. 최적화 Round 1 : find 두번하지 않기 runtime : 18 ms 최적화 Roun.. 더보기
1480. Running Sum of 1d Array 사실 이 문제는 너무 쉬워서 설명할 것도 없지만, 최적화된 알고리즘을 위해, 생각해보아야 할 점을 몇 가지 짚어보겠다. [ Stage 1] 기본이다. Sum list라는 Vector에 숫자를 더해서 Sum_list[i] = Sum_list[i-1] + num[i] 라는 기본 점화식을 바탕으로 풀었다. Runtime: 14 ms [Stage 2] Vector 라는 container는 기본적으로 Push_back 이라는 함수를 제공해주고, Memory에 allocate되는 사이즈가 불명확하다. 그래서 필요 이상의 메모리를 잡고 있다. 따라서 array를 사용할 수 있다면 이 문제에서는 array를 사용하는 것이 맞다. 하지만 return type이 vector이기에 억지로 vector를 써줬다. 하지만 우리.. 더보기
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를 시작한다 .. 더보기