Leetcode709. To Lower Case
Posted DCREN
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode709. To Lower Case相关的知识,希望对你有一定的参考价值。
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();
}
}
以上是关于Leetcode709. To Lower Case的主要内容,如果未能解决你的问题,请参考以下文章