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"
题目:将字符串中的大写字母转换成小写字母
思路:观察ASCII表,如果是大写字母,转换成小写字母就是将其ASCII值加32即可。
代码:
class Solution {
public:
string toLowerCase(string str) {
int length = str.size();
for(int i=0;i<length;i++){
if(str[i]>=65&&str[i]<=90)
str[i] += 32;
}
return str;
}
};