Leetcode/Top Interview 150 46

[Array/String][Easy] 27. Remove Element

https://leetcode.com/problems/remove-element/description Q. 정수배열 nums와 val 이 주어질 때, val을 제외한 nums배열을 다시 nums배열에 출력하고 그 길이를 반환하라.  이때 추가 메모리를 사용하지 말아라.  Solution.  어디서 본 0 뒤로 밀기와 비슷한 문제.   그냥 대상이 아닌 값들을 제외한 값들을 당긴다.  public int RemoveElement(int[] nums, int val) { int idx = 0; for(int q = 0; q   빠른 코드와 별 차이가 없는데, 왜 느린속도로 나오는지 잘... ;;;

[Array/String][Easy] 88. Merge Sorted Array

https://leetcode.com/problems/merge-sorted-array/description Q. 주어진 정렬된 배열 nums1과 nums2를 오름차순으로 merge하라.  이때 nums1과 nums2에 각각 m과 n만큼의 유효한 값이 있다고 가정하고, 결과를 nums1에 넣어라.  Solution. 추가 버퍼 제한이 없으므로, 간단하게 유효한 길이만큼 비교 / 처리 한다.  public void Merge(int[] nums1, int m, int[] nums2, int n) { List ret = new List(); int idx1 = 0, idx2 = 0; for(int q = 0; q =n) val = nums1[idx1++]; e..

Array - Rotate Array

https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/646/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Note : 오른쪽으로 k 만큼 회전시켜라. in-place로 해 보라. Try1. 추가 메모리 사용 ... 할만 하지만 in-place가 아니다. i..

Array - Best Time to Buy and Sell Stock II

https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/564/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Note : 한번에 두개를 동시에 살 수 없다. Solution : 결국 비쌀때 샀다, 쌀때 팔면 되는 것인데, 구간별 누적합이, 전체 최대차의 합과도..

Array - Remove Duplicates from Sorted Array

https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/727/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Notes 정렬된 배열이 인풋임. 추가 메모리 공간을 사용하면 안됨. 배열 길이를 직접 수정하는 것이 아니고, 배열을 수정하고 바르게 읽기 위해 길이 ..