Skip to content

Commit 63d275c

Browse files
committed
4065. Rearrange Array by Removing Distinct Values
1 parent 88a33f1 commit 63d275c

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+
public int[] rearrangeArray(int[] nums) {
3+
// 오름차 순이어야함
4+
// 연속 같은 수 금지
5+
6+
// 숫자 범위 1 ~ 100
7+
int[] cnt = new int[101];
8+
int[] ans = new int[nums.length];
9+
10+
for(int i=0; i<nums.length; i++) cnt[nums[i]]++;
11+
12+
int pos = 0;
13+
14+
for(int i=0; i<101; i++) {
15+
for(int j=0; j<101; j++) {
16+
if(cnt[j]>0) {
17+
ans[pos++] = j;
18+
cnt[j]--;
19+
}
20+
if(pos == nums.length) break;
21+
}
22+
}
23+
24+
return ans;
25+
}
26+
}

0 commit comments

Comments
 (0)