-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2578.java
28 lines (26 loc) · 914 Bytes
/
_2578.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions.thirdthousand;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class _2578 {
public static class Solution1 {
public int splitNum(int num) {
List<Integer> digits = new ArrayList<>();
while (num != 0) {
digits.add(num % 10);
num /= 10;
}
Collections.sort(digits);
StringBuilder nums1 = new StringBuilder();
StringBuilder nums2 = new StringBuilder();
for (int i = 0; i < digits.size(); i++) {
if (nums1.length() < nums2.length()) {
nums1.append(digits.get(i));
} else {
nums2.append(digits.get(i));
}
}
return Integer.parseInt(nums1.toString()) + Integer.parseInt(nums2.toString());
}
}
}