LeetCode刷题

709. To Lower Case

2018-09-14  本文已影响0人  美不胜收oo

描述

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;
        
    }
};
上一篇 下一篇

猜你喜欢

热点阅读