【题目】
实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。
来源:leetcode
链接:https://leetcode-cn.com/problems/to-lower-case/
【示例1】
输入: “Hello”
输出: “hello”
【示例2】
输入: “here”
输出: “here”
【示例3】
输入: “LOVELY”
输出: “lovely”
【代码】
执行用时 :0 ms, 在所有 C++ 提交中击败了100.00% 的用户
内存消耗 :6.3 MB, 在所有 C++ 提交中击败了100.00%的用户
class Solution {
public:
string toLowerCase(string str) {
for(auto &x:str)
if(x>='A'&&x<='Z')
x=x-'A'+'a';
return str;
}
};