-
[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..
-
[알고리즘/자바스크립트] Codility, MaxSliceSum 문제 풀이Algorithm 2020. 5. 31. 22:16
MaxSliceSum A non-empty array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P ≤ Q < N, is called a slice of array A. The sum of a slice (P, Q) is the total of A[P] + A[P+1] + ... + A[Q]. Write a function: function solution(A); that, given an array A consisting of N integers, returns the maximum sum of any slice of A. For example, given array A such that: [3, 2, -6..
-
[알고리즘/자바스크립트] Codility, Dominator 문제 풀이Algorithm 2020. 5. 24. 17:00
Dominator An array A consisting of N integers is given. The dominator of array A is the value that occurs in more than half of the elements of A. For example, consider array A such that [3, 4, 3, 2, 3, -1, 3, 3]. The dominator of A is 3 because it occurs in 5 out of 8 elements of A (namely in those with indices 0, 2, 4, 6 and 7) and 5 is more than a half of 8. Write a function function solution(..
-
[알고리즘/자바스크립트] Codility, PermCheck 문제 풀이Algorithm 2020. 5. 10. 12:30
Codility, PermCheck A non-empty array A consisting of N integers is given. A permutation is a sequence containing each element from 1 to N once, and only once. For example, array A such that: A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2 is a permutation, but array A such that: A[0] = 4 A[1] = 1 A[2] = 3 is not a permutation, because value 2 is missing. The goal is to check whether array A is a permutatio..