标签:app sam for output tco and out 直接 public
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Input: "Hello"
Output: "hello"
Input: "here"
Output: "here"
Input: "LOVELY"
Output: "lovely"
直接遍历就可以
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();
}
}
标签:app sam for output tco and out 直接 public
原文地址:https://www.cnblogs.com/xiagnming/p/9376976.html