709.To Lower Case
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Input: "Hello"
Output: "hello"
Input: "here"
Output: "here"
Input: "LOVELY"
Output: "lovely"
- mine
// O(n)Time O(n)Space
class Solution {
public String toLowerCase(String str) {
// A - Z 65-90 a:97 so a = A + 32
StringBuffer res = new StringBuffer();
char [] resArray = str.toCharArray();
for(int i = 0; i < resArray.length; i++){
if(resArray[i] >= 65 && resArray[i] <= 90){
resArray[i] += 32;
}
res.append(resArray[i]);
}
return res.toString();
}
}