709. To Lower Case
1. Description
Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.
2. Example
Example 1:
Input: s = “Hello”
Output: “hello”
Example 2:
Input: s = “here”
Output: “here”
Example 3:
Input: s = “LOVELY”
Output: “lovely”
3. Constraints
- 1 <= s.length <= 100
- s consists of printable ASCII characters.
4. Solutions
Bit Manipulation
n = str.size()
Time complexity: O(n)
Space complexity: O(n)
class Solution {
public:
string toLowerCase(string &str) {
for(int i = 0; i < str.size(); ++i) {
if('A' <= str[i] && str[i] <= 'Z') {
str[i] |= 32;
}
}
return str;
}
};