To Lower Case
思路一: 遍历,遇到 A-Z 范围内的 char 转换到对应 a-z 范围
public String toLowerCase(String s) {
if (s == null || s.isEmpty()) return s;
int gap = 'a' - 'A';
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
sb.append((char)(s.charAt(i) + gap));
} else {
sb.append(s.charAt(i));
}
}
return sb.toString();
}
标签:String,int,StringBuilder,709,easy,leetcode,charAt
From: https://www.cnblogs.com/iyiluo/p/16804874.html