当前位置:网站首页>Leetcode 709, convert to lowercase

Leetcode 709, convert to lowercase

2022-04-23 20:26:00 Die in a trap

709、 Convert to lowercase

1) Title Description

Give you a string s , Convert the uppercase letters in the string to the same lowercase letters , Returns a new string .

Example 1:

 Input :s = "Hello"
 Output :"hello"

Example 2:

 Input :s = "here"
 Output :"here"

Example 3:

 Input :s = "LOVELY"
 Output :"lovely"

Tips :

  • 1 <= s.length <= 100
  • s from ASCII Composition of printable characters in the character set

2) analysis

Traversal string , In case of uppercase characters , Add 32 Convert to lowercase .

3)C++ Code

class Solution {
    
public:
    string toLowerCase(string s) {
    
        for(int i=0;i<s.length();i++){
    
            if(s[i]>='A'&&s[i]<='Z')
                s[i]+=32;
        }
        return s;
    }
};

版权声明
本文为[Die in a trap]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232023107334.html

随机推荐