LeetCode 125 Valid Palindrome

从零构建:ESP32S3无线DAP-Link调试器的硬件与软件协同设计 本文详细介绍了基于ESP32S3的无线DAP-Link调试器的硬件与软件协同设计,涵盖关键元器件选型、无线通信协议优化、双核任务处理及低功耗调试方案。通过ESP-NOW协议实现低延迟无线调试,结合USB协议栈与双核协同,为嵌入式开发提供高效灵活的调试解决方案。 阅读详情

LeetCode 125

Valid Palindrome

  • Problem Description:
    判断给出的字符串是否是有效的回文字符串。

    具体的题目信息:
    https://leetcode.com/problems/valid-palindrome/description/

  • Solution:

    • 解题思路:用两个变量i和j从字符串两端向中间移动,比较两个变量指向的字符
      (1)如果两个变量指向的字符都是字母,必须是同个字母或者同个字母的大小写
      (2)如果两个变量指向的字符都是数字,必须是同个数字
      (3)如果两个变量指向的字符是不同类型的,必须保证不能一个指向字母,一个指向数字,正确的情况如下:
      • 一个指向字母,一个必须指向标点符号或者空格
      • 一个指向数字,一个必须指向标点符号或者空格
    • 编程实现:
class Solution {
public:
    bool isPalindrome(string s) {
        if (s == "") return true;
        int i = 0, j = s.size()-1;
        while(i <= j) {
            //若对应位置的字符都是字母,必须是同个字母的大小写才返回true,否则返回false
            if (isCharacter(s[i])&&isCharacter(s[j])) {
                if (s[i]+32 == s[j]||s[i]-32 == s[j]||s[i] == s[j]) {
                    i++;
                    j--;
                } else {
                    return false;
                }
            } else if (isNumber(s[i])&&isNumber(s[j])) {
                //若对应位置的字符都是数字,必须是同个数字才返回true,否则返回false
                if (s[i] == s[j]) {
                    i++;
                    j--;
                } else {
                    return false;
                }
            } else {
                //若字符既不是字母也不是数字,前进(后退)一位
                if (!isCharacter(s[i])&&!isNumber(s[i])) {
                    i++;
                } else if (!isCharacter(s[j])&&!isNumber(s[j])) {
                    j--;
                } else if (isCharacter(s[i])) {
                    //若对应位置的两个字符一个是数字,一个是字母,返回true,否则将不是数字或字母的位置向前(后)移动一位
                    if (isNumber(s[j])) {
                        return false;
                    }
                    j--;
                } else if (isCharacter(s[j])) {
                    if (isNumber(s[i])) {
                        return false;
                    }
                    i++;
                }
            }
        }
        return true;
    }
    //判断字符是否字母
    bool isCharacter(char i) {
        if ((i>='a'&&i<='z')||(i>='A'&&i<='Z'))
            return true;
        return false;
    }
    //判断字符是否数字
    bool isNumber(char i) {
        if (i>='0'&&i<='9')
            return true;
        return false;
    }
};
AIGC时代的必备技能:提示词工程(Prompt Engineering)全面指南 本文主要介绍了AIGC时代的重要技能——提示词工程(Prompt Engineering)。文章首先定义了提示词的概念,强调其作为人类与AI沟通桥梁的重要性,并详细阐述了提示词的功能特性,包括输入、大模型处理和输出三个环节。接着,文章探讨了提示工程的重要性,如提高输出质量、节省资源和时间等。随后,文章深入分析了提示词的基本构成要素,包括指令、上下文、输入数据和输出指示符,并提出了提示词的五大基本原则:清晰性与具体性、提供充足的上下文、明确任务与目标、考虑受众和迭代思维。最后,文章介绍了提示词的七大常见技巧 阅读详情

相关推荐

6层高速PCB设计实战:BGA布局与阻抗匹配关键解析

本文深入解析6层高速PCB设计中BGA布局与阻抗匹配的关键技术。通过实战经验分享,详细介绍了六层PCB层叠结构的选择与优化、BGA器件布局技巧、阻抗匹配的实战经验以及高速布线技巧,帮助工程师提升PCB设计水平,确保信号完整性和电源完整性。

weixin_28481133的博客 370

LeetCode-125. 验证回文串(java)

金三银四,又到了刷题月。有时间的话,希望大家还是尽量刷起来咯。帮助往往不是直接体现出来的,但会让你对很多东西的底层实现了解的更深刻。

**My Coding Family** 1930

代谢组学数据分析实战:用R语言从PCA、PLS-DA到OPLS-DA一步步搞定(附代码)

本文详细介绍了使用R语言进行代谢组学数据分析的全流程,从数据预处理到PCA、PLS-DA和OPLS-DA模型构建与验证。通过实际案例和代码示例,帮助研究者掌握关键分析技术,提升数据解读能力,特别适合生命科学领域的研究人员。

weixin_28689507的博客 138

LeetCode125. 验证回文串(含有详细注释)含三种方法

题目表述 方法一: 先将字符串转换为小写字母和数字字符,然后用reverse()翻转数组进行比较 class Solution { public boolean isPalindrome(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i <s.length(); i++) { //获取字符串中第i个字符 char ch=s.charAt(i);

sinat_51673411的博客 268

PID控制器(位置式和增量式)

PID控制算法

zhinian_hao的博客 4527

uniapp:人脸识别功能,已测试,直接复制源码,支持H5,APP安卓。不依赖任何js,SDK。

uniapp人脸识别功能,已测试可直接复制源码,支持H5,APP安卓。不依赖任何js,SDK。 APP效果图:

sunluyi的博客 2235

LeetCode第 125 题:验证回文串(C++)

125. 验证回文串 - 力扣(LeetCode) 简单题,处理好什么时候跳过,什么时候转换就行: class Solution { public: bool isPalindrome(string s) { int n = s.size(); if(n < 2) return true; int i = 0, j = n-1; while(i < j){ while(i < j &

zj 296

Windows 下 Claude Code 使用全记录:从零到一的保姆级图文教程(持续更新)

本文主要介绍了Windows 下 Claude Code 使用全记录:从零到一的保姆级图文教程,希望能对学习使用 Claude Code 的同学们有所帮助。 文章目录 1. 背景 2. 实战教程(2026年最新教程) 2.1 步骤一 Claude Code 环境准备 2.2 步骤二 配置Claude Code 2.3 步骤三 对话 3. 老版本实战教程 3.1 步骤一 配置Node.js 3.2 步骤二 Claude Code配置 3.3 步骤三 配置Claude Code 3.4 步骤四 对话

weixin_43178406的博客 15万+

LeetCode第125题解析

给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。 说明:本题中,我们将空字符串定义为有效的回文串。 示例 1: 输入: "A man, a plan, a canal: Panama" 输出: true 示例 2: 输入: "race a car" 输出: false islower(char c) 是否为小写字母 isupper(char c) 是否为大写字母 isdigit(char c) 是否为数字 isalpha(char c) 是否为字母 isal

blue_coffeei的博客 386

2025年软件测试职业院校技能大赛—ERP管理平台-采购管理采购入库模块测试用例

竞赛对接软件测试相关标准,以“ERP管理平台” 为被测系统,围绕软件测试领域的主流技术及工具,考查选手面 对实际问题的综合分析能力,对测试文档、测试用例的设计能力, 对单元测试、自动化测试、性能测试、接口测试等测试工具及方 法的掌握程度,检验选手团队协作能力、组织规划能力、方法运用能力等。

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 419

PCL Super4PCS算法实现点云粗配准(版本一)【2025最新版】

Win11系统下实现[Super4PCS: Fast Global Pointcloud Registration via Smart Indexing一文中的配准算法。

点云侠的博客 3384

LeetCode第125题_验证回文串

如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后,短语正着读和反着读都一样。则可以认为该短语是一个。字母和数字都属于字母数字字符。给你一个字符串s,如果它是,返回true;否则,返回false。

qq_40263592的博客 1267

自主探索型AI Agent:LLM驱动的好奇心与学习动机

随着人工智能技术的飞速发展,传统的AI系统往往依赖于预设的规则和大量的标注数据,其自主学习和适应新环境的能力有限。自主探索型AI Agent旨在打破这种局限,能够在复杂、未知的环境中自主地进行探索、学习和决策。本文的目的是深入研究在大语言模型(LLM)驱动下,AI Agent如何产生好奇心和学习动机,以及如何实现自主探索的能力。范围涵盖了核心概念、算法原理、数学模型、项目实战、应用场景等多个方面,为读者提供一个全面的技术视角。本文将按照以下结构进行阐述:首先介绍相关背景知识,包括目的、读者和文档结构;

大模型应用工坊 1001

LeetCode 125. Valid Palindrome

LeetCode 125. Valid Palindrome Description Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring other cases. For example, “A man, a plan, a cana

Vimer.Bai的博客 233

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LeetCode刷题:125. Valid Palindrome

LeetCode刷题:125. Valid Palindrome 原题链接:https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. N...

梅森上校的博客 业精于勤荒于嬉,形成于思毁于随。 186

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

[leetcode]125. Valid Palindrome

[leetcode]125. Valid Palindrome Analysis 周五啦周五啦,网上买的小南瓜到啦—— [六一快乐,嘻嘻~] Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: Fo...

weixin_32135877的博客 131

LeetCode: 125. Valid Palindrome

LeetCode: 125. Valid Palindrome 题目描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example: &quot;A man, a plan, a canal: Panama&quot; is ...

杨领well的专栏 700

LeetCode力扣之125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindro...

LeeWei 329

leetcode 125. Valid Palindrome

leetcode 125. Valid Palindrome 题目大意:判断一句话时候为回文,只考虑字母,忽略大小写。 解题思路: 1、判断一个字符是否为数字或者字母 2、在比较的时候不分大小写,因此大写直接全部转为小写 3、在判断回文时直接比较首尾的两个字符

编码之路 299

LeetCode125—Valid Palindrome

LeetCode125—Valid Palindrome

上善若水 806

【LeetCode125】Valid Palindrome

Runtime:8 ms, faster than85.46%ofC++online submissions forValid Palindrome. Memory Usage:9.4 MB, less than61.22%ofC++online submissions forValid Palindrome. class Solution { public: ...

weixin_39458342的博客 154

LeetCode力扣 125. 验证回文串 Valid Palindrome 题解代码 JavaScript

问题https://leetcode-cn.com/problems/valid-palindrome/ 练习使用JavaScript解答 /** * @param {string} s * @return {boolean} */ function judgeChar(c) { if(c >= '0' && c <= '9') return true; if(c >= 'a' && c <= 'z') .

Coding home - 漂流瓶jz 471

【leetCode】leetCode125 Valid Palindrome

题目如下: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. ...

随手积累,典型bug解决。技术栈的系统介绍。 196

【leetcode】【125】Valid Palindrome

一、问题描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a ca

斗code、年华 543

【leetcode】125. Valid Palindrome

125.Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note:For the purpose of this problem, we define empty string as v...

lemonade13的博客 125
上一篇: LeetCode 25 Reverse Nodes in k-Group
下一篇: LeetCode 165 Compare Version Numbers
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值