zoukankan      html  css  js  c++  java
  • [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
    

      

  • 相关阅读:
    【POJ2311】Cutting Game-SG博弈
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
  • 原文地址:https://www.cnblogs.com/guweixin/p/10414063.html
Copyright © 2011-2022 走看看