首页 > 其他 > 详细

【Leetcode】709. To Lower Case

时间:2018-07-27 13:57:41      阅读:314      评论:0      收藏:0      [点我收藏+]

To Lower Case

Description

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"

Discuss

直接遍历就可以

Code

class Solution {
    public String toLowerCase(String str) {
        if (str == null || str.length() == 0) { return null; }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= ‘A‘ && c <= ‘Z‘) {
                c += 32;
                sb.append(Character.toString((char)c));
                continue;
            }
            sb.append(c);
        }
        return sb.toString();
    }
}

【Leetcode】709. To Lower Case

原文:https://www.cnblogs.com/xiagnming/p/9376976.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!