[leetcode] 709. 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"

思路:

大变小,+32;

小变大,-32.

c++代码实现:

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]+32;
        }
        return str;
    }
};

python代码实现:

class Solution(object):
    def toLowerCase(self, str):
            str=str.lower()
            return str

  

原文地址:https://www.cnblogs.com/guweixin/p/10414063.html