LeetCode | 709.转换成小写字母

这道题可以用api也可以自己实现,都不难,大小字母之前相差了32,检查到大写字母时加上32即可

python 复制代码
class Solution(object):
    def toLowerCase(self, s):
        """
        :type s: str
        :rtype: str
        """
        return s.lower()

class Solution {
public:
    string toLowerCase(string s) {
        for (char &c: s) {
            if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
        }
        return s;
    }
};

题解的方法总让我大开眼界,值得学习!

cpp 复制代码
class Solution {
public:
    string toLowerCase(string s) {
        for (char& ch: s) {
            if (ch >= 65 && ch <= 90) {
                ch |= 32;
            }
        }
        return s;
    }
};
相关推荐
SilentSamsara1 天前
迭代器协议:`__iter__` / `__next__` 的完整执行流程
开发语言·人工智能·python·算法·机器学习
AI科技星1 天前
算法联盟ROOT · 全域数学物理卷第20、21、22分册:量子纠缠、隐形场论与时间膨胀
人工智能·算法·数学建模·数据挖掘·机器人
MATLAB代码顾问1 天前
【智能优化】鹈鹕优化算法(POA)原理与Python实现
开发语言·python·算法
AI科技星1 天前
微积分:变化与累积的数学(分层大白话解释版)
人工智能·算法·数学建模·数据挖掘·机器人
sinat_286945191 天前
llm wiki
人工智能·算法·chatgpt
博界IT精灵1 天前
图的遍历(哈喜老师)
数据结构·考研·算法·深度优先
sheeta19981 天前
LeetCode 每日一题笔记 日期:2026.05.10 题目:2770. 达到末尾下标所需的最大跳跃次数
笔记·算法·leetcode
Halo_tjn1 天前
基于异常处理机制 相关知识点
java·开发语言·算法
xingyuzhisuan1 天前
适合微调Llama 3 70B模型的最低GPU配置推荐
运维·人工智能·算法·llama·gpu算力
IJCAST1 天前
Exploring the Frontiers of Complexity: Latest Research from IJCAST
人工智能·深度学习·神经网络·算法