ID | Title | Difficulty | |
---|---|---|---|
Loading... |
709. To Lower Case
Easy
LeetCode
String
Problem
Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.
Example 1:
Input: s = "Hello"
Output: "hello"
Example 2:
Input: s = "here"
Output: "here"
Example 3:
Input: s = "LOVELY"
Output: "lovely"
Constraints:
- $1 <= s.length <= 100$
- s consists of printable ASCII characters.
Code
class Solution {
public String toLowerCase(String s) {
char[] arr = s.toCharArray();
for(int i = 0; i < arr.length; i++) {
char curr = arr[i];
if('A' <= curr && curr <= 'Z') {
arr[i] = (char)(arr[i] - 'A' + 'a');
}
}
return new String(arr);
}
}
按 <- 键看上一题!
708. Insert into a Sorted Circular Linked List
按 -> 键看下一题!
710. Random Pick with Blacklist