Difficulty: Easy Link: Day 24: May Leetcode Challenge
Given a string
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"
1 <= s.length <= 100
sconsists of printable ASCII characters.
The solution is quite straight forward and you might be tempted to use the built-in functions to convert the string directly to lowercase using lowercased(). However, the interviewer might be interested in how you implement it so you should try to solve with your own implementation.
We can easily implement our lowercase function using the fact the ASCII values of lowercase and uppercase alphabets differ by 32 ( ‘A’ = 65, ‘B’ = 66 … ‘a’ = 98, ‘b’ = 99.. so on ).
- Time complexity: O(N) to parse the input string.
- Space complexity: O(N) to keep the output.