Skip to content

Commit 63d4800

Browse files
committed
2022-06-19 update: added "Greatest English Letter in Upper and Lower Case"
1 parent 69622d6 commit 63d4800

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.smlnskgmail.jaman.leetcodejava.easy;
2+
3+
// https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case/
4+
public class GreatestEnglishLetterInUpperAndLowerCase {
5+
6+
private final String input;
7+
8+
public GreatestEnglishLetterInUpperAndLowerCase(String input) {
9+
this.input = input;
10+
}
11+
12+
public String solution() {
13+
char[] upper = new char[128];
14+
char[] lower = new char[128];
15+
for (int i = 0; i < input.length(); i++) {
16+
char curr = input.charAt(i);
17+
if (Character.isUpperCase(curr)) {
18+
upper[curr]++;
19+
} else {
20+
lower[curr]++;
21+
}
22+
}
23+
for (char c = 'Z'; c >= 'A'; c--) {
24+
if (upper[c] > 0 && lower[Character.toLowerCase(c)] > 0) {
25+
return String.valueOf(c);
26+
}
27+
}
28+
return "";
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.smlnskgmail.jaman.leetcodejava.easy;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class GreatestEnglishLetterInUpperAndLowerCaseTest {
8+
9+
@Test
10+
public void defaultTest() {
11+
assertEquals(
12+
"E",
13+
new GreatestEnglishLetterInUpperAndLowerCase("lEeTcOdE").solution()
14+
);
15+
}
16+
17+
}

0 commit comments

Comments
 (0)