From 16b9f93bfb8ea9405d512d3a10810563cfb792d6 Mon Sep 17 00:00:00 2001 From: dmswl6310 Date: Fri, 14 Aug 2026 11:27:15 +0900 Subject: [PATCH] 0814 --- ...ind the Largest Almost Missing Integer.js" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "leetcode3/\355\231\251\354\235\200\354\247\200/3471. Find the Largest Almost Missing Integer.js" diff --git "a/leetcode3/\355\231\251\354\235\200\354\247\200/3471. Find the Largest Almost Missing Integer.js" "b/leetcode3/\355\231\251\354\235\200\354\247\200/3471. Find the Largest Almost Missing Integer.js" new file mode 100644 index 00000000..48baeff1 --- /dev/null +++ "b/leetcode3/\355\231\251\354\235\200\354\247\200/3471. Find the Largest Almost Missing Integer.js" @@ -0,0 +1,32 @@ +/** + * @param {number[]} nums + * @param {number} k + * @return {number} + */ +var largestInteger = function (nums, k) { + if (nums.length < k) return -1; + if (nums.length === k) return Math.max(...nums); + + const group = {}; + let max = -1; + // k가 1이면 중간에 겹치는거 없으면 됨 + // 양쪽 끝은 중간에 숫자가 없으면 안겹침 + + for (let i = 0; i < nums.length; i++) { + if (k !== 1 && (i == 0 || i == nums.length - 1)) continue; + group[nums[i]] = (group[nums[i]] || 0) + 1; + } + + if (k !== 1) { + const left = nums[0]; + const right = nums[nums.length - 1]; + if (left === right) return -1; + if (group[left] === undefined) max = Math.max(max, left); + if (group[right] === undefined) max = Math.max(max, right); + } else { + for (const [key, value] of Object.entries(group)) { + if (value === 1) max = Math.max(key); + } + } + return max; +};