美文网首页
转换成小写字母

转换成小写字母

作者: xialu | 来源:发表于2021-12-12 23:15 被阅读0次

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/to-lower-case

题目描述:

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

示例 1:

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

示例 2:

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

示例 3:

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

代码实现:
class Solution {
    public String toLowerCase(String s) {
        int len = s.length();
        char[] chars = s.toCharArray();
        for (int i = 0; i < len; i++) {
            // ascll A-Z对应数字65-90,a-z对应数字97-122
            if (chars[i] >= 65 && chars[i] <= 90) chars[i] += 32;
        }
        return String.valueOf(chars);
    }
}

相关文章

网友评论

      本文标题:转换成小写字母

      本文链接:https://www.haomeiwen.com/subject/ddidfrtx.html