LeetCode 709 To Lower Case 解題報告
題目要求
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
題目分析及思路
題目要求返回一個字串的小寫形式。可以直接使用lower()函式。如果考慮具體的實現邏輯,則將大寫字元轉成小寫字元即可,判斷字元是否處在‘A’~‘Z’之間,如果是的話,就把它轉成小寫字元。
python程式碼
class Solution:
def toLowerCase(self, str):
"""
:type str: str
:rtype: str
"""
res = ""
for s in str:
if ord(s)>=ord('A') and ord(s)<=ord('Z'):
res += chr(ord(s)-ord('A')+ord('a'))
else:
res += s
return res
相關推薦
LeetCode 709 To Lower Case 解題報告
題目要求 Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. 題目分析及思路 題目要求返回一個字串的小寫形式。可以直接使用lower()函式
[LeetCode]709. To Lower Case
out parameter imp () inpu love ++ strong UNC Implement function ToLowerCase() that has a string parameter str, and returns the same strin
[LeetCode] 709. To Lower Case(C++)
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. Example 1: Input: "Hello" Out
leetcode 709. To Lower Case(水,大寫轉小寫)
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowe
Leetcode——709. To Lower Case
題目原址 題目描述 Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. Exampl
LeetCode 709 To Lower Case 轉換成小寫字母
class Solution { public: string toLowerCase(string str) { for(auto &c:str) { if(c>='A' && c
LeetCode 709.To Lower Case
字母 put NPU 轉化 沒有 運行 des image 分享 Description Implement function ToLowerCase() that has a string parameter str, and returns the same strin
【Leetcode】709. To Lower Case
clas esc scrip int builder cte func pre 遍歷 To Lower Case Description Implement function ToLowerCase() that has a string parameter str, an
【LeetCode】709. To Lower Case題解(C++)
【LeetCode】709. To Lower Case(C++) 709. To Lower Case Describe: Implement function ToLowerCase() that has a string parameter str, a
【Leetcode】To Lower Case
題目大意:把所有的大寫字母轉化為小寫字母 解題方法:判斷字元是否在‘A’-‘Z’中,如果是,則轉換為小寫,如果不是,保留不變既可 Python解法: class Solution(object): def toLowerCase(self, str):
leetcode ( To Lower Case)
Title: To Lower Case 709 Difficulty:Easy 原題leetcode地址: https://leetcode.com/problems/to-lower-case/ 1. 大寫字元加3
709 to lower case 及字串方法總結
/** * @param {string} str * @return {string} */ var toLowerCase = function(str) { var result = ''; for(var i =0; i<
709. To Lower Case
uri 小寫 urn 得到 The public input amp 差值 Algorithm to-lower-case https://leetcode.com/problems/to-lower-case/ 1)problem Implement function T
C#LeetCode刷題之#709-轉換成小寫字母(To Lower Case)
問題 實現函式 ToLowerCase(),該函式接收一個字串引數 str,並將該字串中的大寫字母轉換成小寫字母,之後返回新的字串。 輸入: "Hello" 輸出: "hello" 輸入: "here" 輸出: "here" 輸入:
【LeetCode】709(Java)To Lower Case
Question: Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. 實現函式ToLowerCase st
leetcode 709. 轉換成小寫字母(To Lower Case)
string return class lis 函數 目錄 res lower 大寫 目錄 題目描述: 示例 1: 示例 2: 示例 3: 解法:
[LeetCode] To Lower Case 轉為小寫
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. Example 1: Input: "Hello"
【LeetCode】538. Convert BST to Greater Tree 解題報告(Python)
目錄題目描述題目大意解題方法遞迴日期 題目描述 Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST i
【LeetCode】944. Delete Columns to Make Sorted 解題報告(Python)
目錄題目描述題目大意解題方法日期 題目描述 We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose any set
【LeetCode】849. Maximize Distance to Closest Person 解題報告(Python)
目錄題目描述題目大意解題方法日期 題目描述 In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. Th