1. 程式人生 > >[leetcode]轉換成小寫字母

[leetcode]轉換成小寫字母

709. 轉換成小寫字母

實現函式 ToLowerCase(),該函式接收一個字串引數 str,並將該字串中的大寫字母轉換成小寫字母,之後返回新的字串。

示例 1:

輸入: "Hello"
輸出: "hello"

示例 2:

輸入: "here"
輸出: "here"

示例 3:

輸入: "LOVELY"
輸出: "lovely"

C++解法:

class Solution {
public:
    string toLowerCase(string str) {
        for (auto &c : str)
        {
if (isupper(c)) { c = tolower(c); } } return str; } };