题解:转换成小写字母(709)

版权声明:本文为博主原创文章,转载时注明出处,附加链接即可。 https://blog.csdn.net/cswhit/article/details/81709791

题目链接https://leetcode-cn.com/problems/to-lower-case/description/

实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。

示例 1:

输入: "Hello"
输出: "hello"

示例 2:

输入: "here"
输出: "here"

示例 3:

输入: "LOVELY"
输出: "lovely"

这道题也很简单,尤其是在java有这么多方法的情况下。。。

class Solution {
    public String toLowerCase(String str) {
        char[] arr = str.toCharArray();
        for(int i=0;i<arr.length;i++) {
        	if(arr[i]>='A'&&arr[i]<='Z')
        		arr[i] += 32;
        }
        return String.valueOf(arr);
    }
}

猜你喜欢

转载自blog.csdn.net/cswhit/article/details/81709791