0709. to Lower Case

709. To Lower Case #

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.

Problem Statement #

Given a string s, convert the uppercase letters in the string to the same lowercase letters and return the new string.

Solution #

  • Easy problem: convert the uppercase letters in the string to lowercase letters.

Code #

func toLowerCase(s string) string {
    runes := [] rune(s)
    diff := 'a' - 'A'
    for i := 0; i < len(s); i++ {
        if runes[i] >= 'A' && runes[i] <= 'Z' {
            runes[i] += diff
        }
    }
    return string(runes)
}

Calendar Jun 25, 2026
Edit Edit this page
Total visits:   You are visitor No.
中文