Two pointer
LeetCode / Two Pointer / 75번 / Sort Color / JS
더보기문제는 0, 1, 2로 이루어진 배열을 다음 규칙에 따라 정렬하라는 문제이다. 0은 배열의 앞쪽에 배치1은 그 다음에 배치2는 배열의 끝쪽에 배치그냥 쉽게 오름차순으로 정렬하면된다. 하지만 다음과 같은 제한사항이 있다.공간 복잡도 O(1)원소의 총 개수는 n이고, 1 /** * @param {number[]} nums * @return {void} Do not return anything, modify nums in-place instead. */var sortColors = function (nums) { const COLOR = { RED: 0, WHITE: 1, BLUE: 2, }; let left = 0; let right = nums.length - 1; let ..
LeetCode / Two Pointer / 16번 / 3Sum Closese / JS
3Sum Closest - LeetCode Can you solve this real interview question? 3Sum Closest - Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each inp leetcode.com 주어진 nums 배열에서 3개의 수를 뽑아서 더했을 때, target 값과 가장 가까운 값을 반환하면 된다. /** * @param {numbe..