2023年8月18日 星期五

8/19 (每日一題 轉換小寫)

Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.

 

Example 1:

Input: s = "Hello"
Output: "hello"

Example 2:

Input: s = "here"
Output: "here"

Example 3:

Input: s = "LOVELY"
Output: "lovely"

 

Constraints:

  • 1 <= s.length <= 100
  • s consists of printable ASCII characters.

class Solution:
    def toLowerCase(self, s: str) -> str:
        return s.lower()
       
________________________
class Solution:
    def toLowerCase(self, s: str) -> str:
        return ''.join([chr(ord(i) + 32) if (ord(i) <= 90 and ord(i) >= 65) else i for i in s])

標籤:

0 個意見:

張貼留言

訂閱 張貼留言 [Atom]

<< 首頁