Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
To Lower Case
class Solution {
public boolean isUpper(char x) {
return 'A' <= x && x <= 'Z';
}
public char toLower(char x) {
return (char) ((int)x | 32);
}
public String toLowerCase(String str) {
StringBuilder sb = new StringBuilder();
for (char x : str.toCharArray()) {
sb.append(isUpper(x) ? toLower(x) : x);
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment