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码中大写字母比小写字母小32,直接加上32变成小写字母。
class Solution {
public:
string toLowerCase(string str) {
for(char& c : str)
if(c >= 'A' && c<='Z') c += 32;
return str;
}
};
原文地址:https://www.cnblogs.com/ysugyl/p/9594568.html
时间: 2024-11-03 11:34:24