본문 바로가기

반응형

리트코드

(55)
[리트코드] 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. 코드 처음엔 ..
[리트코드] 131. Palindrome Partitioning - js 1. 문제 https://leetcode.com/problems/palindrome-partitioning/ { if(!left.length && arr.length) answer.push(arr); for(let i=1;i { let back = str.split("").reverse().join(""); if(str === back) return true; else false; }
[리트코드] 1. Two Sum - js 1. 문제 https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Can you solve this real interview question? Two Sum - Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not leetcode.com 2. 코드 /** * @param {number[]} nums * @param {number} target * @re..
[리트코드] 739. Daily Temperatures - js 1. 문제 https://leetcode.com/problems/daily-temperatures/description/ Daily Temperatures - LeetCode Can you solve this real interview question? Daily Temperatures - Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer leetcode.com 2. 코드 /** * @param {number[]} t..

반응형