Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Example 1:
Input: "Hello" Output: "hello"
Example 2:
Input: "here" Output: "here"
Example 3:
Input: "LOVELY" Output: "lovely"
<SOLVE>
import java.util.*;
class Solution {
public String toLowerCase(String str) {
char[] result = new char[str.length()];
for(int i=0; i<str.length(); i++){
result[i] = str.toLowerCase().charAt(i);
}
//String res = new String();
StringBuffer res = new StringBuffer();
for (int i = 0; i < result.length; i++) {
//res += Character.toString(result[i]);
res.append(result[i]);
}
return res.toString();
}
}
class Solution {
public String toLowerCase(String str) {
char[] result = new char[str.length()];
for(int i=0; i<str.length(); i++){
result[i] = str.toLowerCase().charAt(i);
}
//String res = new String();
StringBuffer res = new StringBuffer();
for (int i = 0; i < result.length; i++) {
//res += Character.toString(result[i]);
res.append(result[i]);
}
return res.toString();
}
}
'Amazon > Leetcode - etc' 카테고리의 다른 글
804. Unique Morse Code Words (Google) (0) | 2018.07.28 |
---|