[LeetCode] 709. To Lower Case(C++)

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"
class Solution {
public:
    string toLowerCase(string str) {
        for (int i = 0; i < str.size(); i++) {
            if (str[i] >= 'A' && str[i] <= 'Z') {
                str[i] = str[i] - 'A' + 'a';
            }
        }
        return str;
    }
};

我的提交执行用时
已经战胜 100.00 % 的 cpp 提交记录

猜你喜欢

转载自blog.csdn.net/chenyingying_/article/details/83411736