From 9c20ee5cae9d75fcb7272315f22d6e4a006e835b Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Fri, 14 Aug 2026 23:53:02 +0900 Subject: [PATCH] Create 3471. Find the Largest Almost Missing Integer.py --- ...ind the Largest Almost Missing Integer.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/3471. Find the Largest Almost Missing Integer.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/3471. Find the Largest Almost Missing Integer.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/3471. Find the Largest Almost Missing Integer.py" new file mode 100644 index 00000000..0e9cb452 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/3471. Find the Largest Almost Missing Integer.py" @@ -0,0 +1,29 @@ +from collections import Counter + +class Solution: + def largestInteger(self, nums: List[int], k: int) -> int: + n = len(nums) + counter = Counter(nums) + + if k == n: + return max(nums) + + if k == 1: + ans = -1 + + for num in nums: + if counter[num] == 1: + ans = max(ans, num) + + return ans + + # 1 < k < n + ans = -1 + + if counter[nums[0]] == 1: + ans = max(ans, nums[0]) + + if counter[nums[-1]] == 1: + ans = max(ans, nums[-1]) + + return ans