JIAKAOBO

LeetCode

venmo
wechat

感谢赞助!

  • ㊗️
  • 大家
  • offer
  • 多多!

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);
    }
}