leetcode709—To Lower Case

时间:2024-11-21 14:06:37

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;
    }
};