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:
def toLowerCase(self, str: str) -> str:
if not str:
return str
n = len(str)
res = []
for i in range(n):
c = ord(str[i])
if c >= 65 and c <= 90:
c += 32
res.append(chr(c))
return ''.join(res)
class Solution {
public String toLowerCase(String str) {
int n;
if (str == null || (n = str.length()) == 0) return str;
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; ++i) {
boolean isUpper = chars[i] >= 'A' && chars[i] <= 'Z';
if (isUpper) chars[i] += 32;
}
return new String(chars);
}
}