1. What I learned
a. .lower()
It changes every character to lower case. But using ‘.lower()’ takes a lot of time.
ex) print(‘HELLO’.lower()) –> ‘hello’
b. ord()
It returns an integer representing the Unicode character.
ex) print(ord(‘a)) –> 97
2. How I sloved
Using ‘.lower()’ took longer, so I approached all the letters. I checked if the letters were capital letters. In capital letters I changed the letter to Unicode and added 32. If it wasn’t capital letters, I just connected them.
3. Code
class Solution:
def toLowerCase(self, str: str) -> str:
return ''.join([chr(ord(c)+32) if c.isupper() else c for c in str])
class Solution:
def toLowerCase(self, str: str) -> str:
return str.lower()
4. Result
Runtime : 16 ms(99.52%), Memory usage : 12.9 MB(100.00%)
(Runtime can be different by a system even if it is a same code.)