일단 쉬운 문제 많이 풀기!!
class Solution:
def toLowerCase(self, str: str) -> str:
str = str.lower()
return str
하지만 이렇게 lower api를 쓰면 너무 쉬우니 아래 처럼 문자열 처리를 해보자 ㅎㅎ
ord api를 사용하면, A라는 char의 ascii값을 얻을 수 있다.
chr api를 사용하면 ascii값을 다시 char로 변환할 수 있다.
class Solution:
def toLowerCase(self, str: str) -> str:
ans = ""
for i in range(len(str)):
if(ord(str[i]) >= ord('A') and ord(str[i]) <= ord('Z')):
print("%d" % (ord(str[i]) - ord('A')))
ans += chr(ord(str[i]) - ord('A') + ord('a'))
else:
ans += str[i]
return ans
'Algorithm > LeetCode 문제 풀이' 카테고리의 다른 글
[LeetCode 14. Longest Common Prefix ] Easy (19주차 6/10, 20/150) (0) | 2019.05.12 |
---|---|
[LeetCode 13. Roman to Integer] Easy (19주차 5/10, 19/150) (0) | 2019.05.12 |
[LeetCode 1. Two Sum Easy] O(N^2) 로 풀었다.(19주차 3/10, 17/150) (0) | 2019.05.11 |
[LeetCode 344. Reverse String Easy] Python 자신감 뿜뿜 (0) | 2019.05.11 |
[LeetCode 541. Reverse String II] python 오랜만에 LeetCode를 풀었다. (0) | 2019.05.11 |