본문 바로가기

반응형

전체 글

(501)
[리트코드] 64. Minimum Path Sum - js 1. 문제 https://leetcode.com/problems/minimum-path-sum/ Minimum Path Sum - LeetCode Can you solve this real interview question? Minimum Path Sum - Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or rig leetcode.com 2. 코드 처음 푼 코드) 타임아웃 나의 풀이는 타임아웃이 떴다. 정답을 보니 재귀..
[리트코드] 56. Merge Intervals - js 1. 문제 https://leetcode.com/problems/merge-intervals/ 2. 코드 /** * @param {number[][]} intervals * @return {number[][]} */ var merge = function(intervals) { let stack = []; intervals.sort((a,b) => a[0] - b[0]); let newIntervals = intervals.slice(); stack.push(newIntervals.shift()); for(let i=1;i
[리트코드] 704. Binary Search - js 1. 문제 https://leetcode.com/problems/binary-search/ Binary Search - LeetCode Can you solve this real interview question? Binary Search - Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. leetcode.com 2. 코드 /** * @param {number[]} nums * @param {number}..
[리트코드] 198. House Robber - js 1. 문제 https://leetcode.com/problems/house-robber/description/ House Robber - LeetCode Can you solve this real interview question? House Robber - You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent ho leetcode.com 2. 코드 원래 작성한 코드) 당연한 오답.. 무조건 하나 건너 하나 선택한..
[리트코드] 347. Top K Frequent Elements - js (해시) 1. 문제 https://leetcode.com/problems/top-k-frequent-elements/description/ Top K Frequent Elements - LeetCode Can you solve this real interview question? Top K Frequent Elements - Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] leetcode.com 2. 코드 해시 맵의 value 별 정렬을 ..
[리트코드] 189. Rotate Array - js 1. 문제 https://leetcode.com/problems/rotate-array/ Rotate Array - LeetCode Can you solve this real interview question? Rotate Array - Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 step leetcode.com 2. 코드 이 문제의 첫번째 핵심은 파라미터로 들어온 nums 배열을 반환하는 것이다. 새로운 배열을 ..
[리트코드] 169. Majority Element - js (해시) 1. 문제 https://leetcode.com/problems/majority-element/ 2. 코드 /** * @param {number[]} nums * @return {number} */ var majorityElement = function(nums) { let map = new Map(); for(let n of nums){ map.set(n, (map.get(n) || 0) + 1); } for(let [k,v] of map){ if(v >= nums.length / 2) return k; } };
[리트코드] 238. Product of Array Except Self - js 1. 문제 https://leetcode.com/problems/product-of-array-except-self/description/ Product of Array Except Self - LeetCode Can you solve this real interview question? Product of Array Except Self - Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nu leetcode.com 2. 코드 처음엔 ..

반응형