[leetcode] 709. To Lower Case

网友投稿 806 2022-08-22

[leetcode] 709. To Lower Case

[leetcode] 709. To Lower Case

Description

Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.

Example 1:

Input: "Hello"Output: "hello"

Example 2:

Input: "here"Output: "here"

Example 3:

Input: "LOVELY"Output: "lovely"

分析

题目的意思是:把字符串里面的大写字母转换为小写,这道题是想考怎么实现这个过程,过程也很简单,用ascii码,然后大写字母和小写字母相差32,如果知道这些就很好实现了。

代码

class Solution: def toLowerCase(self, str: str) -> str: t='' for ch in str: if(ch>='A' and ch<='Z'): t+=chr(ord(ch)+32) else: t+=ch return t

参考文献

​​[LeetCode] Python short 1 line ASCII & string method solutions​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:[leetcode] 1600. Throne Inheritance
下一篇:iOS开发总结-Xcode常见错误(xcode运行ios)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~