본문 바로가기

leetcode5

[LeetCode] 26. Remove Duplicates from Sorted Array 06.28.20240. Before We BeginI write my code even though my code is ridiculous as is the question just in case someone wonders what the heck is going on and why the judging seems odd.1. Problem2. My Code/** * @param {number[]} nums * @return {number} */var removeDuplicates = function(nums) { const s = new Set(nums); const result = [...s]; const k = nums.length; nums.length = 0; res.. 2024. 6. 28.
[LeetCode] 169. Majority Element 06.27.2024 1. Problem2. My Code/** * @param {number[]} nums * @return {number} */var majorityElement = function(nums) { var obj = Object(); nums.forEach((e) => { if (obj[e]) obj[e]++; else obj[e] = 1; }); let max = 0; Object.entries(obj).forEach((pair) => { const standard = parseInt(nums.length / 2); if (pair[1] > standard) max = pair[0]; }); .. 2024. 6. 27.
[LeetCode] 78. Subsets 01.29.2024 1. Problem 2. My code var subsets = function(nums) { let result = []; for(let i=0; i 2024. 1. 29.
[LeetCode] 446. Arithmetic Slices II - Subsequence 01.07.2024 1. Problem 2. The Things I tried I tried backtracking or a recursive function. But I could not make it and also the quiality of code was bad too. 3. Solution 3-1. Code var numberOfArithmeticSlices = function(nums) { const n = nums.length; let total_count = 0; const dp = new Array(n).fill().map(() => new Map()); for (let i = 1; i < n; ++i) { for (let j = 0; j < i; ++j) { const diff = n.. 2024. 1. 8.
[LeetCode] 46. Permutations 01.03.2024 1. Problem 2. Before 2-1. My Code /** * @param {number[]} nums * @return {number[][]} */ var permute = function(nums) { const len = nums.length; let result = []; result.push(nums); result.push(nums.reverse()); for(var i = 0; i < len; i++ ) { for(var j = 0; j < len-1; j++){ nums[j+1], nums[j] = nums[j], nums[j+1]; if (!(nums in result)) result.push(nums); } }; console.log(result); retu.. 2024. 1. 3.