码迷,mamicode.com
首页 > 其他好文 > 详细

【Leetcode】709. To Lower Case

时间:2018-07-27 14:39:48      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:app   sam   for   output   tco   and   out   直接   public   

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

标签:app   sam   for   output   tco   and   out   直接   public   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!