목록array (7)
N
https://leetcode.com/problems/number-of-zero-filled-subarrays/ Number of Zero-Filled Subarrays - LeetCode Can you solve this real interview question? Number of Zero-Filled Subarrays - Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = leetcode.com const zeroFilledSubarray =..
https://leetcode.com/problems/longest-increasing-subsequence/ Longest Increasing Subsequence - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com /** * @param {number[]} nums * @return {number} */ var lengthOfLIS = function(nums) { const length = nums.length; const dp = Array.from({le..
https://leetcode.com/problems/candy/ Candy - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com var candy = function(ratings) { const { length } = ratings; const fromLeft = Array.from({length}, () => 1); const fromRight = Array.from({length}, () => 1); let answer = 0; for(let i = 1; i..
https://leetcode.com/problems/wiggle-subsequence/ Wiggle Subsequence - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 배열에서 조건에 맞는 길이의 최대값을 찾아야 한다. 인접한 수의 차가 + - + - ... or - + - +... 면 된다. answer = 1부터 시작하는데, 이는 0번째 값은 무조건 답이 될 수 있는 최소값이 되기 때문이다. flag를 이용해 현재 값 차이가 양수인지, 음수인지 ..
https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ Find All Numbers Disappeared in an Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com nums 배열에서 없는 수를 answer에 담아 리턴하면 된다. 1 부터 nums.length 까지의 수가 nums에 담겨있다. check라는 배열을 length + 1 크기로 선언하고 false로 초기화한다. n..
https://leetcode.com/problems/valid-sudoku/ Valid Sudoku - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com /** * @param {character[][]} board * @return {boolean} */ var isValidSudoku = function(board) { const rowCheck = (num, x, y) => { for(let i = x + 1; i < 9; i++){ if(board[i][y..

배열 순차 리스트 연관된 데이터를 연속적인 형태로 구성된 구조를 가진다. 배열에 포함된 원소는 순서대로 번호(index)가 붙으며, 0부터 시작한다. 고정된 크기를 가지며, 일반적으로는 동적으로 크기를 늘릴 수 없다.(C, C++..) 그러나 JS와 같은 스크립트 언어는 동적으로 크기가 증감된다. 원하는 원소의 번호(index)를 알고 있다면 O(1)로 원소를 찾을 수 있다. 원소를 삭제하면 해당 번호(index)에 빈 자리가 된다. 삭제 후 빈 자리를 채우기 위해 O(n)이 소요된다. 중간에 요소를 추가하기 위해서도 O(n)이 소요된다. 추가와 삭제가 반복되는 로직은 배열이 추천되지 않는다! 배열 생성 방법 4가지 const arr1 = []; const arr2 = [1, 2, 3, 4, 5]; co..