LeetCode in Kotlin

709. To Lower Case

Easy

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:

Solution

class Solution {
    fun toLowerCase(s: String): String {
        val c = s.toCharArray()
        for (i in s.indices) {
            if (c[i] in 'A'..'Z') {
                c[i] = (c[i].code - 'A'.code + 'a'.code).toChar()
            }
        }
        return String(c)
    }
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy