forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2309.java
31 lines (29 loc) · 1.04 KB
/
_2309.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
29
30
31
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class _2309 {
public static class Solution1 {
public String greatestLetter(String s) {
List<Character> lowercase = new ArrayList<>();
List<Character> uppercase = new ArrayList<>();
for (char c : s.toCharArray()) {
if (Character.isLowerCase(c)) {
lowercase.add(c);
} else {
uppercase.add(c);
}
}
Collections.sort(uppercase, Collections.reverseOrder());
Collections.sort(lowercase, Collections.reverseOrder());
for (int i = 0; i < uppercase.size(); i++) {
for (int j = 0; j < lowercase.size(); j++) {
if (Character.toLowerCase(uppercase.get(i)) == lowercase.get(j)) {
return uppercase.get(i) + "";
}
}
}
return "";
}
}
}