Skip to content

Commit 90c7eec

Browse files
authored
Create 4065. Rearrange Array by Removing Distinct Values.py
1 parent a135ead commit 90c7eec

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def rearrangeArray(self, nums: list[int]) -> list[int]:
3+
n = len(nums)
4+
visited = set()
5+
ans = []
6+
7+
while len(visited) != n:
8+
9+
candids = set()
10+
for i in range(n):
11+
if i in visited:
12+
continue
13+
if nums[i] in candids:
14+
continue
15+
visited.add(i)
16+
candids.add(nums[i])
17+
18+
temp = []
19+
for num in candids:
20+
temp.append(num)
21+
temp.sort()
22+
for num in temp:
23+
ans.append(num)
24+
25+
return ans
26+

0 commit comments

Comments
 (0)