Skip to content

Commit 070b830

Browse files
Create 2309.-Greatest-English-Letter-in-Upper-and-Lower-Case.java
Contest 298 problem 1
1 parent 5981542 commit 070b830

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//Contest 298 brute-force feel free to share any improvements
2+
class Solution {
3+
public String greatestLetter(String s) {
4+
HashSet<Integer> set = new HashSet<>();
5+
int ans = -1;
6+
for (int i = 0; i<s.length(); i++) {
7+
if (set.contains((s.charAt(i)-32)) || set.contains((s.charAt(i)+32)))
8+
ans = Math.max(ans, (int)Character.toUpperCase(s.charAt(i)));
9+
set.add(0+s.charAt(i));
10+
}
11+
return ans==-1?"":(char)ans+"";
12+
}
13+
}

0 commit comments

Comments
 (0)