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"

代码

class Solution {
public:
    string toLowerCase(string str) {
        
        for(int i = 0;i<str.size();i++)
        {
            if(str[i]<='Z'&&str[i]>='A')
            {
                str[i] = str[i]-('A'-'a');
            }
        }
        
        return str;
        
    }
};
    原文作者:美不胜收oo
    原文地址: https://www.jianshu.com/p/bbf4809ac476
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞