大写A到Z的ascii码为65~90,小写a到z为97到122,即小写字母的ascii等于大写+32
注意会有其他非字母的ascii字符,不发生转换
class Solution:
def toLowerCase(self, s: str) -> str:
res = []
for c in s:
asc = ord(c) #c的ascii码
if asc >= 65 and asc <= 90: #说明是大写字母
lower = chr(asc + 32) #转小写
res.append(lower)
else:
res.append(c)
return ''.join(res)