LeetCode 0709. To Lower Case Solution in Java, Python, C++, JavaScript, Go & Rust | Explanation + Code

CoderIndeed
0
0709. To Lower Case

Description

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.

Solutions

Solution 1

PythonJavaC++GoTypeScriptRustC
class Solution: def toLowerCase(self, s: str) -> str: return "".join([chr(ord(c) | 32) if c.isupper() else c for c in s])(code-box)

Solution 2

TypeScriptRust
function toLowerCase(s: string): string { return [...s].map(c => String.fromCharCode(c.charCodeAt(0) | 32)).join(''); }(code-box)

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !