Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert a string to lowercase in LeetCode

2025-04-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report