709. To Lower Case

作者: fred_33c7 | 来源:发表于2018-07-17 21:50 被阅读0次

    题目地址: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'))
    

    相关文章

      网友评论

        本文标题:709. To Lower Case

        本文链接:https://www.haomeiwen.com/subject/tyxnpftx.html