[LeetCode] 709. To Lower Case

Posted arcsinw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] 709. To Lower Case相关的知识,希望对你有一定的参考价值。

Description

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"

Analyse

将字符串全变成小写的,简单题

for循环字符串内每个字符,如果是大写字母则变成小写字母,通过ASCII的方式

A   65
Z   90
a   97
z   122
string toLowerCase(string str)

    for (int i = 0; i < str.length(); i++)
    
        if ( 'A' <= str[i] && str[i] <= 'Z')
        
            str[i] = str[i] + ('a' - 'A');
            //str[i] = str[i] + 32;
            //str[i] = str[i] | 32; //32的二进制是0010 0000, str[i] | 32是把str[i]代表32的那个二进制位变成1,那个位如果原来为0和32与运算相当于+32
        
    
    return str;

以上是关于[LeetCode] 709. To Lower Case的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode709. To Lower Case

leetcode 709. To Lower Case

LeetCode 709.To Lower Case

[LeetCode] 709. To Lower Case

[LeetCode]709. To Lower Case

LeetCode 709 To Lower Case 解题报告