实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。
输入: "Hello"
输出: "hello"
输入: "here"
输出: "here"
输入: "LOVELY"
输出: "lovely"
class Solution {
public:
string toLowerCase(string str) {
string res = "";
for(char ch : str){
if(ch >= 'A' && ch <= 'Z'){
res += char(ch - 'A' + 'a');
}else{
res += ch;
}
}
return res;
}
};
leetcode 709. 转换成小写字母(To Lower Case)
原文:https://www.cnblogs.com/zhanzq/p/10609335.html