Python3 not str own conversion bit lower lowercase letters

Python3 not str own conversion bit lower lowercase letters

Original title https://leetcode-cn.com/problems/to-lower-case/

Title:
not allowed to use the string comes lower () API!
Implementing a function toLowerCase (), the function takes a string argument str, and converts the string to uppercase to lowercase, and then returns the new string.
Example 1:

输入: "Hello"
输出: "hello"

Example 2:

输入: "here"
输出: "here"

Example 3:

输入: "LOVELY"
输出: "lovely"

Problem solving:

class Solution:
    def toLowerCase(self, str: str) -> str:
        return ''.join(list(map(lambda x:chr(ord(x)|32), str))) # 变小写就和32按位或,变大写就和-33按位与,大变小小变大则和32按位异或
Published 24 original articles · won praise 0 · Views 413

Guess you like

Origin blog.csdn.net/qq_18138105/article/details/105170712