Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert a string to lowercase in LeetCode

Shulou Source: shulou.com Published: 2022-06-01 13:04:37 10月03日 Update

This article mainly shows you "how to convert strings into lowercase in LeetCode". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to convert strings into lowercase in LeetCode.

Title:

Implement an algorithm that converts a string to lowercase.

Method one

When you see this question, I don't know what your idea is. If you are familiar with API in Python, the first thing that comes to mind is to directly use the str.lower () method to achieve it. This can be done in actual development, but that is certainly not the purpose of this question.

Def to_lower_case (text):

Method 2 of return text.lower ()

You may think of the ASCII code value of a character. 26 English letters correspond to a value in ASCII. The uppercase axiz corresponds to an ASCII value of 65. 90, and the lowercase axiz is 97. 122, and they are all contiguous, with a difference of 32 between the uppercase and lowercase values of the same letter, so if a letter is in the range of 65 to 90, adding it to 32 is the corresponding lowercase letter. Here, the conversion between ascii code values and letters requires two functions, ord and chr.

> ord ('a')

ninety-seven

> > chr (97)

'a'

Def to_lower_case (text):

New_text = ""

For c in text:

If 65

Tags: Letter lowercase character string form method content size article uppercase that is train of thought way learning help elegance one-to-one correspondence between two function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Docker Redmi Huawei MariaDB