Skip to content

Commit 1f1796e

Browse files
committed
Runtime: 9 ms (Top 70.77%) | Memory: 42.3 MB (Top 96.77%)
1 parent 7c3174f commit 1f1796e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
// Runtime: 9 ms (Top 70.77%) | Memory: 42.3 MB (Top 96.77%)
12
class Solution {
23
public int[] sortByBits(int[] arr) {
3-
4+
45
Integer[] arrInt = new Integer[arr.length];
5-
6+
67
for(int i=0;i<arr.length;i++) {
78
arrInt[i]=arr[i];
89
}
9-
10+
1011
Arrays.sort(arrInt, new Comparator<Integer>() {
1112
@Override
1213
public int compare(Integer a, Integer b) {
@@ -18,20 +19,20 @@ public int compare(Integer a, Integer b) {
1819
return aBits-bBits;
1920
}
2021
});
21-
22+
2223
for(int i=0;i<arr.length;i++) {
2324
arr[i]=arrInt[i];
2425
}
2526
return arr;
2627
}
27-
28+
2829
public int numOfBits(int a) {
2930
int bits=0;
3031
while(a!=0) {
3132
bits+=a&1;
3233
a=a>>>1;
3334
}
34-
35+
3536
return bits;
3637
}
3738
}

0 commit comments

Comments
 (0)