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, s: str) -> str:
return ''.join([chr(ord(c) | 32) if ord('A') <= ord(c) <= ord('Z') else c for c in s])
class Solution {
public String toLowerCase(String s) {
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; ++i) {
if (chars[i] >= 'A' && chars[i] <= 'Z') {
chars[i] |= 32;
}
}
return new String(chars);
}
}
class Solution {
public:
string toLowerCase(string s) {
for (char& c : s)
if (c >= 'A' && c <= 'Z')
c |= 32;
return s;
}
};
func toLowerCase(s string) string {
sb := &strings.Builder{}
sb.Grow(len(s))
for _, c := range s {
if c >= 'A' && c <= 'Z' {
c |= 32
}
sb.WriteRune(c)
}
return sb.String()
}