[LeetCode]709. 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"

思路: ASCII码中大写字母比小写字母小32,直接加上32变成小写字母。

class Solution {
public:
    string toLowerCase(string str) {
        for(char& c : str)
            if(c >= 'A' && c<='Z') c += 32;

        return str;
    }
};

原文地址:https://www.cnblogs.com/ysugyl/p/9594568.html

时间: 2024-11-03 11:34:24

[LeetCode]709. To Lower Case的相关文章

709. To Lower Case

Algorithm to-lower-case https://leetcode.com/problems/to-lower-case/ 1)problem Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. Example 1: Input: "Hello" Output: "hello" Exampl

LeetCode--To Lower Case &amp; Remove Outermost Parentheses (Easy)

709. To Lower Case(Easy) 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"

LeetCode算法题-To Lower Case(Java实现)

这是悦乐书的第301次更新,第320篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第169题(顺位题号是709).实现具有字符串参数str的函数ToLowerCase():以小写形式返回相同的字符串.例如: 输入:"Hello" 输出:"hello" 输入:"here" 输出:"here" 输入:"LOVELY" 输出:"lovely" 本次解题使用的开发工

[LeetCode] 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: "L

(Easy) To Lower Case LeetCode

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: In

2. To Lower Case

Title: 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" Note: None Analysi

LeetCode题解之 Letter Case Permutation

1.题目描述 2.问题分析 可以使用递归的方法解决,参考了别人的答案才写出来的. 3.代码 1 vector<string> letterCasePermutation(string S) { 2 vector<string> res ; 3 recursion( S,res,0 ); 4 return res; 5 6 } 7 8 void recursion(string & s , vector<string> &r ,int p){ 9 if(

arts-week6

Algorithm 830. Positions of Large Groups - LeetCode 75. Sort Colors - LeetCode 859. Buddy Strings - LeetCode 791. Custom Sort String - LeetCode 804. Unique Morse Code Words - LeetCode 877. Stone Game - LeetCode 890. Find and Replace Pattern - LeetCod

LeetCode Python 位操作 1

Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 >> num >> 2 == num / 2**2 取反 ~ ~num == -(num + 1) 1. Single Number Given an array of integers, every element appears twice except for one. Find