Problem
Given a strings, return the string after replacing every uppercase letter with the same lowercase letter.
Examples
Constraints
- 1 <= s.length <= 100
- s consists of printable ASCII characters.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Tested Python solution for LeetCode 709 with 16 pytest cases. Generate a practice environment with lcpy.
lcpy gen -n 709 # by problem number
lcpy gen -s to_lower_case # by problem name
s, return the string after replacing every uppercase letter with the same lowercase letter.
Input: s = "Hello"
Output: "hello"
Input: s = "here"
Output: "here"
Input: s = "LOVELY"
Output: "lovely"
class Solution:
# Time: O(n)
# Space: O(n)
def to_lower_case(self, s: str) -> str:
out: list[str] = []
for ch in s:
code = ord(ch)
out.append(chr(code + 32) if 65 <= code <= 90 else ch)
return "".join(out)
| Time | Space |
|---|---|
| O(n) | O(n) |