[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

  

上一篇:[NOI2016]区间 线段树


下一篇:docker 安装mysql 忽略table大小写问题