File tree 1 file changed +25
-2
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
3
6
public class _709 {
4
7
public static class Solution1 {
5
- public String toLowerCase (String str ) {
6
- return str .toLowerCase ();
8
+ public String toLowerCase (String s ) {
9
+ return s .toLowerCase ();
10
+ }
11
+ }
12
+
13
+ public static class Solution2 {
14
+ public String toLowerCase (String s ) {
15
+ Map <Character , Character > map = new HashMap <>();
16
+ String upper = new String ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
17
+ String lower = new String ("abcdefghijklmnopqrstuvwxyz" );
18
+ for (int i = 0 ; i < upper .length (); i ++) {
19
+ map .put (upper .charAt (i ), lower .charAt (i ));
20
+ }
21
+ StringBuilder sb = new StringBuilder ();
22
+ for (int i = 0 ; i < s .length (); i ++) {
23
+ if (map .containsKey (s .charAt (i ))) {
24
+ sb .append (map .get (s .charAt (i )));
25
+ } else {
26
+ sb .append (s .charAt (i ));
27
+ }
28
+ }
29
+ return sb .toString ();
7
30
}
8
31
}
9
32
}
You can’t perform that action at this time.
0 commit comments