class Solution {
public int convertTime(String current, String correct) {
String[] split1 = current.split(":");
int hour1 = Integer.valueOf(split1[0]);
int mimute1 = Integer.valueOf(split1[1]);
int time1 = 60 * hour1 + mimute1;
String[] split2 = correct.split(":");
int hour2 = Integer.valueOf(split2[0]);
int mimute2 = Integer.valueOf(split2[1]);
int time2 = 60 * hour2 + mimute2;
int diff = time2 - time1;
int ans = 0;
while (diff > 0) {
if (diff >= 60) {
diff -= 60;
++ans;
} else if (diff >= 15) {
diff -= 15;
++ans;
} else if (diff >= 5) {
diff -= 5;
++ans;
} else if (diff >= 1) {
diff -= 1;
++ans;
}
}
return ans;
}
}
class Solution {
public int largestInteger(int num) {
List<Integer> odds = new ArrayList<>();
List<Integer> evens = new ArrayList<>();
List<Integer> isOdd = new ArrayList<>();
while (num > 0) {
int temp = num % 10;
num /= 10;
if (temp % 2 == 0) {
evens.add(temp);
isOdd.add(0);
} else {
odds.add(temp);
isOdd.add(1);
}
}
Collections.sort(odds);
Collections.sort(evens);
int ans = 0;
int i = odds.size() - 1;
int j = evens.size() - 1;
for (int k = isOdd.size() - 1; k >= 0; --k) {
int isOd = isOdd.get(k);
ans *= 10;
if (isOd == 0) {
ans += evens.get(j--);
} else {
ans += odds.get(i--);
}
}
return ans;
}
}
class Solution {
public int findClosestNumber(int[] nums) {
int ans = -100001;
for (int num : nums) {
if (Math.abs(ans) > Math.abs(num) ) {
ans = num;
} else if (Math.abs(ans) == Math.abs(num) ) {
ans = Math.max(ans, num);
}
}
return ans;
}
}