forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_709.java
32 lines (29 loc) · 1010 Bytes
/
_709.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
32
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _709 {
public static class Solution1 {
public String toLowerCase(String s) {
return s.toLowerCase();
}
}
public static class Solution2 {
public String toLowerCase(String s) {
Map<Character, Character> map = new HashMap<>();
String upper = new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
String lower = new String("abcdefghijklmnopqrstuvwxyz");
for (int i = 0; i < upper.length(); i++) {
map.put(upper.charAt(i), lower.charAt(i));
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (map.containsKey(s.charAt(i))) {
sb.append(map.get(s.charAt(i)));
} else {
sb.append(s.charAt(i));
}
}
return sb.toString();
}
}
}