Largest Number After Digit Swaps by Parity LeetCode solution in Java

1
class Solution {
2
public int largestInteger(int num) {
3
PriorityQueue<Integer> opq = new PriorityQueue<>();
4
PriorityQueue<Integer> epq = new PriorityQueue<>();
5
int bnum = num;
6
while (num > 0) {
7
int cur = num % 10;
8
if (cur % 2 == 1) {
9
opq.add(cur);
10
} else {
11
epq.add(cur);
12
}
13
num /= 10;
14
}
15
StringBuilder sb = new StringBuilder();
16
num = bnum;
17
while (num > 0) {
18
int cur = num % 10;
19
if (cur % 2 == 1) sb.insert(0, opq.poll());
20
else sb.insert(0, epq.poll());
21
num /= 10;
22
}
23
return Integer.parseInt(sb.toString());
24
}
25
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0