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"
class Solution {
public String toLowerCase(String str) {
if(str == null){
return str;
}
char[] array = str.toCharArray();
char[] result = new char[array.length];
for(int i=0; i< array.length; i++){
char ch = array[i];
if(ch >= 65 && ch <= 90){
ch += 32;
}
result[i] = ch;
}
return new String(result);
}
}