목록Leet Code 알고리즘 (179)
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/capacity-to-ship-packages-within-d-days/description/ Capacity To Ship Packages Within D Days - LeetCode Can you solve this real interview question? Capacity To Ship Packages Within D Days - A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[i]. Each day, we leetcod..
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/diagonal-traverse/ Diagonal Traverse - 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[][]} mat * @return {number[]} */ var findDiagonalOrder = function(mat) { const answer = []; const diagonalX = [-1, 1]; const diagonalY = [1, -1]..
https://leetcode.com/problems/game-of-life/ Game of Life - 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 Conway game의 룰을 따른 시뮬레이션 현재의 셀의 상태와 주변 8방향의 셀 상태를 파악해 Next state를 구하는 문제. 룰을 잘 읽으면 쉽게 구현할 수 있는 문제다. const gameOfLife = (board) => { const m = board.length; const n = board[0]...
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/maximum-units-on-a-truck/ Maximum Units on a Truck - 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 정렬을 활용한 문제. 주어진 boxTypes 배열을 정렬하는데, boxTypes[1] 번째 요소의 내림차순으로 정렬을 해준다. 이후 for문을 이용해 truckSize가 채워지는 만큼 박스를 트럭에 채운다. 만약 truckSize - num이 0 이상이라면 모든 박스를 ..