-
[LeetCode] Array101 - Find All Numbers Disappeared in an ArrayAlgorithm 2021. 5. 29. 22:59
Find All Numbers Disappeared in an Array Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Example 1: Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Example 2: Example 2: Input: nums = [1,1] Output: [2] Constraints: n == nums.length 1 [1, , , 4, ] - 그리고 숫자가 들어있는 칸만 남겨둔다 => [1, 4] 이렇게 풀면 총 3번 ..
-
[LeetCode] Array101 - Third Maximum NumberAlgorithm 2021. 5. 23. 15:09
Third Maximum Number Given integer array nums, return the third maximum number in this array. If the third maximum does not exist, return the maximum number. Example 1: Input: nums = [3,2,1] Output: 1 Explanation: The third maximum is 1. Example 2: Example 2: Input: nums = [1,2] Output: 2 Explanation: The third maximum does not exist, so the maximum (2) is returned instead. Example 3: Example 3:..
-
[LeetCode] Arrays101 - Valid Mountain ArrayAlgorithm 2021. 5. 16. 19:40
Valid Mountain Array Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 arr[i + 1] > ... > arr[arr.length - 1] Example 1: Input: arr = [2,1] Output: false Example 2: Input: arr = [..
-
[LeetCode] Arrays101 - Remove Duplicates from Sorted ArrayAlgorithm 2021. 5. 9. 15:57
Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Clarification: Confused why the returned value is an integer but your answer is an array? Note that the input..
-
[LeetCode] Arrays101 - Remove ElementAlgorithm 2021. 5. 9. 14:51
Remove Element Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Clarification: Confused why the returned value is an in..
-
[LeetCode] Arrays101 - Merge Sorted ArrayAlgorithm 2021. 5. 8. 23:58
Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has a size equal to m + n such that it has enough space to hold additional elements from nums2. Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,..
-
[LeetCode] Arrays101 - Squares of a Sorted ArrayAlgorithm 2021. 5. 8. 23:38
아주 오랜만에 다시 시작한 알고리즘 문제 풀기! (그동안 노션으로 휘리릭~ 간단하게 정리하는 것에 맛들려서 블로그에 손을 안댔는데 매우 반성하고 있다. 하하...) Squares of a Sorted Array Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, i..
-
JavaScript, 숫자 타입이 아닌 값을 숫자로 바꾸는 다양한 방법 - feat. Number()/parseInt/Unary plus(+)/Unary negation(-)Frontend 2020. 11. 8. 18:51
JavaScript에서 숫자 타입이 아닌 값을 숫자로 바꿀 때는 주로 Number나 parseInt를 사용한다. Number When used as a function, Number(value) converts a string or other value to the Number type. If the value can't be converted, it returns NaN. Number는 함수로 사용 시 string이나 다른 값들을 Number type으로 변환해준다. 만약에 값을 변환할 수 없을 때는 NaN을 리턴한다. parseInt The parseInt() function parses a string argument and returns an integer of the specified radix..
-
알아두면 유용한 TypeScript의 Utility type 정리Frontend 2020. 6. 21. 22:11
TypeScript의 Utility Type 업무할 때 종종 튀어 나오는 애들인데 내가 잘 모르는 것 같아서 한 번 쭉 정리해보았다. 정리하다보니 진작 알아뒀으면 유용하게 많이 썼을텐데 싶은 것들이 엄청 많다. 심심할 때마다 다시 읽어봐야겠다. Partial 주어진 Type의 모든 property를 optional로 세팅한 Type을 구성한다. 다시 말해 주어진 Type의 모든 부분 집합 type을 return한다. 즉, 아래 Todo interface에 title과 description이 정의되어 있는데, Todo 중에서 일부 속성으로만 이루어진 type을 지정하고 싶을 때, Partial을 사용하면 된다. interface Todo { title: string; description: string; ..
-
[Svelte] Svelte 기초 - Svelte로 Form 다루기 / Custom Event Dispatch하기Frontend 2020. 6. 21. 21:01
Form 다루기 이제 svelte에서 input 요소들을 어떻게 다루는 지 살펴보도록 하자. - Input Text - AddPersonForm.svelte Add a new person Add Person 먼저 form 태그에 3가지 input 태그를 만들고 각 input에 변수를 binding했다. 그리고 handleSubmit 함수를 form 태그에 submit 이벤트로 등록해주었다. 이 때 지난 번에 소개한 preventDefault라는 Event modifier를 이용하여 form 태그의 기본 동작을 막아주었다. 이제 form 태그 안에 있는 button을 클릭하면 submit 이벤트가 발생하여 handleSubmit 함수가 실행될 것이다. (bind:value는 아래 글에서 자세히 설명했으므로..