LeetCode - Algorithms - 709. To Lower Case

Problem

709. To Lower Case

Java

bitwise operator

© 10 cool bitwise operator hacks and tricks every programmer must know - Quickly convert character to lowercase and uppercase

1
2
3
4
5
6
7
8
9
class Solution {
public String toLowerCase(String str) {
char[] a = str.toCharArray();
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] | ' ');
}
return String.valueOf(a);
}
}

Submission Detail

  • 8 / 8 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for To Lower Case.
  • Memory Usage: 36.9 MB, less than 46.27% of Java online submissions for To Lower Case.

jdk

1
2
3
4
5
class Solution {
public String toLowerCase(String str) {
return str.toLowerCase();
}
}

Submission Detail

  • 8 / 8 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for To Lower Case.
  • Memory Usage: 37.6 MB, less than 6.49% of Java online submissions for To Lower Case.

2

1
2
3
4
5
6
7
8
9
class Solution {
public String toLowerCase(String str) {
String s = "";
for(int i=0;i<str.length();i++) {
s += Character.toLowerCase(str.charAt(i));
}
return s;
}
}

Submission Detail

  • 8 / 8 test cases passed.
  • Runtime: 4 ms, faster than 10.90% of Java online submissions for To Lower Case.
  • Memory Usage: 37.4 MB, less than 6.49% of Java online submissions for To Lower Case.