Skip to content

Commit 0ab90da

Browse files
Merge pull request #2175 from CodingTestStudy2/변지협
[변지협] 2026/10/14
2 parents 636e10b + e76af03 commit 0ab90da

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
1. 아이디어 :
3+
- 매 라운드마다 nums에 남아있는 서로 다른 값들을 하나씩 제거해 오름차순으로 ans에 이어붙인다.
4+
- Counter로 남은 값들의 개수를 세고, 등장하는 key마다 nums에서 하나씩 제거해 tmp에 모은 뒤 정렬해 ans에 extend.
5+
- nums가 빌 때까지 반복.
6+
7+
2. 시간복잡도 :
8+
o(n^2) (최대값의 개수만큼 라운드 반복 * Counter/remove 비용)
9+
10+
3. 자료구조/알고리즘 :
11+
해시맵(Counter), 정렬, 시뮬레이션
12+
13+
"""
14+
15+
from collections import Counter
16+
17+
18+
class Solution:
19+
def rearrangeArray(self, nums: list[int]) -> list[int]:
20+
ans = []
21+
while nums:
22+
tmp = []
23+
c = Counter(nums)
24+
for key in c.keys():
25+
nums.remove(key)
26+
tmp.append(key)
27+
tmp.sort()
28+
ans.extend(tmp)
29+
30+
return ans

0 commit comments

Comments
 (0)