709. To Lower Case

题目地址:https://leetcode.com/problems/to-lower-case/description/
大意:单词或句子里面的大写字母转化为小写字母

思路:各个语言都包装好了这种方法。不用的用ascii码转换也行

# 709. To Lower Case

class Solution:
    def toLowerCase(self, str):
        """
        :type str: str
        :rtype: str
        """
        return str.lower()

    def toLowerCase2(self, str):
        """
        :type str: str
        :rtype: str
        """
        # return [chr(ord(i) + 32) for i in str if 65 <= ord(i) <= 90]
        result = ''
        for i in str:
            index = ord(i)
            if 65 <= index <= 90:
                result += chr(index + 32)
            else:
                result += i
        return result

a = Solution()
print(a.toLowerCase2('Hello'))




所有题目解题方法和答案代码地址:https://github.com/fredfeng0326/LeetCode

你可能感兴趣的:(709. To Lower Case)