File tree 2 files changed +48
-0
lines changed
main/java/com/smlnskgmail/jaman/leetcodejava/easy
test/java/com/smlnskgmail/jaman/leetcodejava/easy
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments