1. 程式人生 > >leetcode709—To Lower Case

leetcode709—To Lower Case

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"
想法:利用c++裡面的函式transform,進行大小寫轉換。
transform(str.begin(), str.end(), str.begin(), ::toupper);變成大寫
transform(str.begin(), str.end(), str.begin(), ::tolower);變成小寫

class Solution {
public:
    string toLowerCase(string str) {
        transform(str.begin(), str.end(), str.begin(), ::tolower);
        return str;
    }
};