Skip to content

Commit 478cecf

Browse files
Merge pull request #2177 from CodingTestStudy2/염혜정
[염혜정] 2026/10/14
2 parents c69fcd6 + 2b91c59 commit 478cecf

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public int[] rearrangeArray(int[] nums) {
3+
int[] count = new int[101];
4+
int maxCount = 0;
5+
6+
for (int num : nums) {
7+
count[num]++;
8+
maxCount = Math.max(maxCount, count[num]);
9+
}
10+
11+
int[] answer = new int[nums.length];
12+
int index = 0;
13+
14+
for (int round = 1; round <= maxCount; round++) {
15+
for (int value = 1; value <= 100; value++) {
16+
if (count[value] >= round) {
17+
answer[index++] = value;
18+
}
19+
}
20+
}
21+
22+
return answer;
23+
}
24+
}

0 commit comments

Comments
 (0)