力扣(LeetCode)709. 转换成小写字母

力扣(LeetCode)709. 转换成小写字母_第1张图片
思路:
可以直接调用tolower()函数,也可以对其ASCII码进行操作

#include
#include
#include
using namespace std;
class Solution
{
public:
    string toLowerCase(string str)
    {
        string str1 = "";
//        for(auto c:str)
//            str1+= tolower(c);
        for(auto c:str)
        {
            if(c>=65 && c<=90)
                c = c+32;
            str1+=c;
        }
        return str1;
    }
};

int main()
{
    string str = "Hello";
    string str1 = "";
    Solution s;
    str1 = s.toLowerCase(str);
    cout<

你可能感兴趣的:(LeetCode)