본문 바로가기

반응형

리트코드

(55)
[리트코드] 2784. Check if Array is Good - js 1. 문제 https://leetcode.com/problems/check-if-array-is-good/ 2. 코드 /** * @param {number[]} nums * @return {boolean} */ var isGood = function(nums) { let sortedNums = nums.sort((a,b) => a-b); if(sortedNums[sortedNums.length-1] !== sortedNums[sortedNums.length-2]) return false; for(let i=0;i
[리트코드] 75. Sort Colors - js 1. 문제 https://leetcode.com/problems/sort-colors/ 2. 코드 /** * @param {number[]} nums * @return {void} Do not return anything, modify nums in-place instead. */ var sortColors = function(nums) { for(let i=0;i
[리트코드] 35. Search Insert Position - js (이진탐색) 1. 문제 https://leetcode.com/problems/search-insert-position/ Search Insert Position - LeetCode Can you solve this real interview question? Search Insert Position - Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must w leetcode.com 2. 코드 /** * @param {number[]} nums ..
[리트코드] 283. Move Zeroes - js (투포인터) 1. 문제 https://leetcode.com/problems/move-zeroes/description/ Move Zeroes - LeetCode Can you solve this real interview question? Move Zeroes - Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. E leetcode.com 2. 코드 처음 작성한 코드) 오답 nums = [0,0,1] 일 경우 답이 [0,1..
[리트코드] 3. Longest Substring Without Repeating Characters - js (슬라이딩 윈도우) 1. 문제 https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
[리트코드] 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}..

반응형