版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010339647/article/details/89435220
题目
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Example 1:
Input: “Hello”
Output: “hello”
Example 2:
Input: “here”
Output: “here”
Example 3:
Input: “LOVELY”
Output: “lovely”
链接
https://leetcode.com/problems/to-lower-case/
分析
直接用代码库中的方法或者采用逐个字符转换的形式。
代码
class Solution {
public String toLowerCase(String str) {
return str.toLowerCase();
}
}
class Solution(object):
def toLowerCase(self, str):
"""
:type str: str
:rtype: str
"""
return str.lower()
class Solution(object):
def toLowerCase(self, str):
"""
:type str: str
:rtype: str
"""
lower = [chr(i) for i in range(97,123)]
upper = [chr(i) for i in range(65,91)]
re = []
for i in range(0, len(str)):
if str[i] in upper:
re.append(lower[upper.index(str[i])])
else:
re.append(str[i])
return ''.join(re)