Majority Element1 [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. 이전 1 다음