標題: 709To Lower Case

程度:簡單

題目:

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

Example 1:

Input: "Hello"
Output: "hello"

 

簡單說把所有字串的大寫改成小寫,收工

非常簡單的送分題

 

那具體要如何改呢?

其實你只要把字串切成1個1個的字元,並且轉成小寫

再存回去即可囉~~

 

來上個程式碼吧~~

class Solution {
public:
    string toLowerCase(string str) {
    int i;
for(i=0;i<str.size();i++)
    {
       str[i]= (char)tolower(str[i]);
    }
        return str;
        
    }
};

 

 

arrow
arrow

    kyo 發表在 痞客邦 留言(0) 人氣()