当前位置:网站首页>LeetCode 709、转换成小写字母

LeetCode 709、转换成小写字母

2022-04-23 20:23:00 亡于灬

709、转换成小写字母

1)题目描述

给你一个字符串 s ,将该字符串中的大写字母转换成相同的小写字母,返回新的字符串。

示例 1:

输入:s = "Hello"
输出:"hello"

示例 2:

输入:s = "here"
输出:"here"

示例 3:

输入:s = "LOVELY"
输出:"lovely"

提示:

  • 1 <= s.length <= 100
  • s 由 ASCII 字符集中的可打印字符组成

2)分析

遍历字符串,若是大写字符,加32转换成小写字母。

3)C++代码

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;
    }
};

版权声明
本文为[亡于灬]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_38342510/article/details/124360505

随机推荐