From 90c7eec115ca27736abdb286f8c0dd84efc562a9 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Wed, 14 Oct 2026 11:01:31 +0900 Subject: [PATCH] Create 4065. Rearrange Array by Removing Distinct Values.py --- ...ange Array by Removing Distinct Values.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" new file mode 100644 index 00000000..f57edc8f --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" @@ -0,0 +1,26 @@ +class Solution: + def rearrangeArray(self, nums: list[int]) -> list[int]: + n = len(nums) + visited = set() + ans = [] + + while len(visited) != n: + + candids = set() + for i in range(n): + if i in visited: + continue + if nums[i] in candids: + continue + visited.add(i) + candids.add(nums[i]) + + temp = [] + for num in candids: + temp.append(num) + temp.sort() + for num in temp: + ans.append(num) + + return ans +