-
[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..
-
[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는 아래 글에서 자세히 설명했으므로..
-
[Svelte] Svelte 기초 - Svelte로 Modal 만들기 (Conditional Styles / Event Forwarding / Props / Event Modifiers / Slots)Frontend 2020. 6. 21. 20:27
이제 Svelte로 Modal을 만들어보려고 한다. Modal 컴포넌트를 만들어서 해당 컴포넌트를 특정 condition에 의해 보여줬다 안보여줬다 toggle할 수 있도록 만들어야 할 것이다. 일단 App.svelte와 동일한 폴더에 Modal.svelte를 만들어보자. Conditional Styles {#if showModal} Sign up for offers! {/if} 위 Modal 컴포넌트는 showModal 변수가 true일 때만 보여진다. 그리고 class:promo={ isPromo }는 바로 conditional styles이다. 즉, 조건에 따라 class name을 줬다 안줬다 할 수 있는 기능이다. class:promo={ isPromo } 라고 하면 isPromo 변수가 tru..
-
[Svelte] Svelte 기초 - Loop / If-else blocks / Inline Event HandlersFrontend 2020. 6. 21. 17:55
Loops {#each people as person (person.id)} {person.name} {person.age} years old, {person.hairColor} hair {:else} There are no people to show... {/each} svelte에서 loop을 돌며 dom 을 그릴 때는 each block을 사용한다. 중간에 else block을 이용해서 만약에 배열에 데이터가 하나도 없을 경우 보여 줄 dom을 결정할 수도 있다. {#each people as person, index (person.id)} {index + 1} : {person.name} {/each} 이렇게 index를 가져올 수도 있다. {#each people as { name }, inde..