#Leetcode# 709. To Lower Case

https://leetcode.com/problems/to-lower-case/

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) {
        string ans = "";
        int len = str.length();
        for(int i = 0; i < len; i ++) {
            if(str[i] >= 'A' && str[i] <= 'Z') ans += (str[i] + 32);
            else ans += str[i];
        }
        return ans;
    }
};

  大写变小写(凑数题) 今天 Leetcode 写到 200 就不写了

FH

猜你喜欢

转载自www.cnblogs.com/zlrrrr/p/10409587.html
今日推荐