- Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathToLowerCase709.java
More file actions
Latest commit
34 lines (31 loc) · 767 Bytes
/
Copy pathToLowerCase709.java
File metadata and controls
34 lines (31 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* mplement 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"
*/
publicclassToLowerCase709 {
publicStringtoLowerCase(Stringstr) {
returnstr.toLowerCase();
}
/**
* https://leetcode.com/problems/to-lower-case/discuss/148993/Java-no-library-methods
*/
publicStringtoLowerCase2(Stringstr) {
char[] a = str.toCharArray();
for (inti = 0; i < a.length; i++)
if ('A' <= a[i] && a[i] <= 'Z')
a[i] = (char) (a[i] - 'A' + 'a');
returnnewString(a);
}
}