其他分享
首页 > 其他分享> > 709. To Lower Case*

709. To Lower Case*

作者:互联网

709. To Lower Case*

https://leetcode.com/problems/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++ 实现 1

查询 ASCII 码表, 发现 A ~ Z 的码为 65 ~ 90, 而 a~z 的码为 97~122.

class Solution {
public:
    string toLowerCase(string str) {
        for (auto &c : str)
            if (c >= 65 && c <= 90)
                c += 32;
        return str;
    }
};
珍妮的选择 发布了226 篇原创文章 · 获赞 6 · 访问量 1万+ 私信 关注

标签:Case,Lower,709,str,Output,Input,Example,string
来源: https://blog.csdn.net/Eric_1993/article/details/104104599