LeetCode算法题-Longest Palindrome(Java实现-五种解法)

Longest Palindrome (最长回文子串) 一个序列(字符串)S=a1a2...an 的倒置 S 为 anan-1...a1。而 S 的子串定义为 S 中任何连续的一部分,如 aiai+1...aj 是 S 的一个子串,但aiai+2... 则不是 S 的子串。如果一个序列 S=S,则 S 称为回文序列。本文接下来将研究一个有趣的问题:给定一个序列 S,找出 S 中最长的回文子串。 在详细分析各个算法之前,先给出一个概览:简单的 阅读详情

这是悦乐书的第220次更新,第232篇原创

01 看题和准备

今天介绍的是LeetCode算法题中Easy级别的第87题(顺位题号是409)。给定一个由小写或大写字母组成的字符串,找到可以用这些字母构建的最长的回文长度。这是区分大小写的,例如“Aa”在这里不被视为回文。例如:

输入:“abccccdd”
输出:7
说明:可以建造的最长的回文是“dccaccd”,其长度为7。

注意:假设给定字符串的长度不超过1,010。

本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java语言编写和测试。

02 第一种解法

给定的字符范围是大小写字母,因此使用一个长度为256的整型数组,来存储字符串s中每个字符出现的次数。想要构成回文,字符串中的各个字符出现的次数分为两种情况:一是该字符出现偶数次,二是该字符出现奇数次。出现偶数次可以直接拿来使用,只要放在对称位置即可;出现奇数次时,如果是1次,那么该字符只能当做回文的中心且只能用一次,如果大于1次,则其偶数次部分可以直接使用,并且多余的1次可以当做回文的中心且只能使用一次。

此解法的时间复杂度是O(n),空间复杂度是O(1)。

public int longestPalindrome(String s) {
    int[] arr = new int[256];
    for (int i=0; i<s.length(); i++) {
        arr[s.charAt(i)]++;
    }
    int count = 0;
    int single = 0;
    for (int j=0; j<arr.length; j++) {
        if (arr[j]%2 == 0) {
            count += arr[j];
        } else {
            count += arr[j]-1;
            single = 1;
        }
    }
    return count+single;
}

03 第二种解法

此解法的思路和第一种解法一致,只是在计数判断那里有点区别。对数组中当前元素直接除以2得到商,再乘以2,得到当前字符可以使用的次数,但是同样需要判断奇数次元素,如果当前元素是奇数,并且count是偶数,即count之前没遇到奇数,那么count自加1,并且只会执行一次,因为回文字符串中心只能是一次。

此解法的时间复杂度是O(n),空间复杂度是O(1)。

public int longestPalindrome2(String s) {
    int[] arr = new int[256];
    for (int i=0; i<s.length(); i++) {
        arr[s.charAt(i)]++;
    }
    int count = 0;
    for (int j=0; j<arr.length; j++) {
        count += (arr[j]/2)*2;
        if (arr[j]%2 == 1 && count%2 == 0) {
            count++;
        }
    }
    return count;
}

04 第三种解法

此解法思路和第二种解法一致,有区别的是判断出现奇数次字符并且count加1的逻辑从循环体中抽出来了,放在了最后。如果count和字符串s的长度做比较时,相等则说明s中的字符都是出现偶数次,不相等则说明s中有出现奇数次的字符,count就需要加1,且只能加1次。

此解法的时间复杂度是O(n),空间复杂度是O(1)。

public int longestPalindrome3(String s) {
    int[] arr = new int[256];
    for (int i=0; i<s.length(); i++) {
        arr[s.charAt(i)]++;
    }
    int count = 0;
    for (int j=0; j<arr.length; j++) {
        count += (arr[j]/2)*2;
    }
    return count == s.length() ? count : count+1;
}

05 第四种解法

使用HashSet,如果当前字符已经在set中存在,那么count加2,并且要移除当前字符;如果不存在,就add进set中。最后判断set是否为空,如果不为空,则说明有些字符出现了奇数次,就只能当做回文字符组中心来用,且只能用一次。

此解法的时间复杂度是O(n),虽然使用了contains方法,但是HashSet内存储的数据不会达到O(n)规模,因此遍历判断是否包含当前字符需要的最多判断次数为52次,即O(52*n),也即O(n)。

空间复杂度是O(1),虽然使用了HashSet,但是字符的范围只是大小写字母,最大长度是52,可以看做是一个常量。

public int longestPalindrome4(String s) {
    Set<Character> set = new HashSet<Character>();
    int count = 0;
    for (int i=0; i<s.length(); i++) {
        if (set.contains(s.charAt(i))) {
            count = count + 2;
            set.remove(s.charAt(i));
        } else {
            set.add(s.charAt(i));
        }
    }
    if (!set.isEmpty()) {
        count = count + 1;
    }
    return count;
}

06 第五种解法

参照第四种解法的思路,我们同样可以使用数组来操作。数组的长度控制在58,因为a到z是从97到122,A到Z是从65到90,中间相隔58个数。将s变为字符数组,如果当前字符表示的十进制数,在数组中对应的元素为0就自加1,否则就自减1,然后count加2,最后再去判断数组中的元素有没有大于0的存在,如果存在即表示有字符出现了奇数次,然后count需要加1,且只用加一次。

public int longestPalindrome5(String s) {
    int[] arr = new int[58];
    int count = 0;
    for (char ch : s.toCharArray()) {
        if (arr[ch-'A'] == 0) {
            arr[ch-'A']++;
        } else {
            arr[ch-'A']--;
            count += 2;
        }
    }
    for (int j=0; j<arr.length; j++) {
        if (arr[j] > 0) {
            count += 1;
            break;
        }
    }
    return count;
}

07 小结

算法专题目前已连续日更超过两个月,算法题文章87+篇,公众号对话框回复【数据结构与算法】、【算法】、【数据结构】中的任一关键词,获取系列文章合集。

以上就是全部内容,如果大家有什么好的解法思路、建议或者其他问题,可以下方留言交流,点赞、留言、转发就是对我最大的回报和支持!

LeetCode算法题个人笔记【简单1-5】【c#和c++】 今天开始在算法打拼力 复制会出蜜汁bug,那正好手敲一遍题目熟练熟练,坚持下去看英文!没有以后再说 链接地址 第一题 : Two Sum Given an array of integers, return indices(index 的复数形式之一) of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, an 阅读详情

相关推荐

VCU128开发板上手记:搞定100G以太网IP核与QSFP光模块的那些坑

本文详细介绍了在VCU128开发板上实现100G以太网IP核与QSFP光模块调试的实战经验。从硬件准备、IP核配置到QSFP模块控制信号处理,文章揭示了数据手册中未提及的关键细节,并提供了优化参数和压力测试方案,帮助开发者快速解决UltraScale+平台下的高速以太网部署难题。

weixin_30740295的博客 521

leetcode-第五题-longestPalindrome

package com.freshbin.leetcode.from1to100.medium; import java.util.HashMap; import java.util.Map; /** * 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。 * 示例 1: * 输入: "babad" * 输出: "bab" * 注意: "aba...

freshbin000的博客 420

用OpenNI2获取奥比中光Astra Pro及 Astra Pro SM输出的深度图(win,linux arm64 x64平台)

搞了一个奥比中光Astra Pro,想在windows平台,和linux rk3588 上获取深度信息,之前的驱动下载已经不好用了。

babytiger的专栏 1309

关于C语言的字符串的个人理解,大一新生,写错不要喷。一

//字符串和字符串数组 void main() { //对于输入字符串的方式有,a已经是字符串的地址了 char a[100]; gets(a);/*但是不建议使用gets进行字符串的 输入,因为会出现数据的溢出,从而产生bug,建议 使用fgets进行字符串的输入,因为这样可以防止数据 的溢出,确保精度*/ scanf("%s",&a); fgets(a,100,sdin);//但是使用了fgets在输出的时候会 //自动生成一个回车换行键 //fgets的输入有点不

走出那座山 292

从Multibit到Debanking:芯片设计中的时序优化完整流程解析(含真实案例)

本文深入解析芯片设计中Multibit技术与Debanking的时序优化完整流程,结合7nm移动SoC真实案例,详细探讨Multibit的核心优势、实施条件及潜在风险,并提供Debanking的触发时机与操作策略。通过平衡Multibit与Debanking,工程师可有效优化PPA(Power-Performance-Area),提升芯片设计效率。

weixin_30316097的博客 462

从补码原理到实践:RISC-V中addi指令的符号扩展机制详解

本文深入解析了RISC-V架构中addi指令的符号扩展机制。从补码的数学原理出发,详细阐述了12位立即数在指令编码中如何通过符号位进行扩展,并结合lui指令,揭示了加载任意32位立即数的正确方法与实践陷阱,帮助开发者编写高效可靠的底层代码。

weixin_29161719的博客 141

leetcode 5 - longestPalindrome

给定一个字符串 S,找出 S 中最长的回文子串。 你可以假设 S 的最大长度是 1000, 并且存在一个唯一的最长回文子串。 string longestPalindrome(string s) { string longest; int n = s.size(); if(n <= 1) return s; //构造一个矩阵,consdier matrix[i][j] as s[i] -> s[j] 是否为回文。 //使用char或int可能会导致`内存限制错误` //vector&

虾球 246

【NVIDIA Jetson Orin系列 - 安装NVIDIA SDK Manager】

NVIDIA Jetson Orin - 安装NVIDIA SDK Manager

dally2的博客 2697

Longest Palindrome(C++最长回文串)

Longest Palindrome(C++最长回文串)

coolsunxu的博客 253

Electron - Electron failed to install correctly, please delete node_modules/electron and try install

Electron安装失败:Electron failed to install correctly, please delete node_modules/electron and try installing again,electron安装报错:Electron failed to install correctly...解决方案,Electron 未能正确安装,请删除 node_modules/electron,然后再次尝试安装,如何解决这个问题,手把手教你解决,在yarn dev时报错,electr

🏆 前端领域优质创作者 4372

在 SAP Fiori 中正确配置 Group 角色:从 PFCG 分配到首页呈现的完整链路

摘要:SAP Fiori项目中,用户登录后能否看到应用往往取决于角色配置而非前端开发。关键在于通过PFCG角色将launchpad designer中创建的tile group关联到用户角色。Catalog是应用池,group是用户首页可见的工作区。正确配置后,用户会看到角色对应的默认分组,同时保留个性化调整能力。项目实施中常见问题是应用开发完成但未正确配置group与角色关联,导致业务用户无法在首页看到应用入口。(150字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 169

LeetCode算法题-Longest Palindrome(五种解法)

这是悦乐书的第220次更新,第232篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第87题(顺位题号是409)。给定一个由小写或大写字母组成的字符串,找到可以用这些字母构建的最长的回文长度。这是区分大小写的,例如“Aa”在这里不被视为回文。例如: 输入:“abccccdd” 输出:7 说明:可以建造的最长的回文是“dccaccd”,其长度为7。 注意:假设给定字符串...

weixin_33739523的博客 237

Qt代码-无人机地面站系统

无人机地面站系统是无人机与操作员交互的核心枢纽,需实现**无人机状态监控**(位置、姿态、电池等)、**实时通信**(基于MAVLink协议)、**任务规划**(航点编辑、航线生成)、**地图显示**(无人机位置与航迹)、**参数配置**(传感器校准、飞行模式设置)等核心功能。地面站作为`MAV_COMP_ID_GCS`(地面控制站组件ID=255),无人机通常为`MAV_COMP_ID_AUTOPILOT1`(组件ID=1)。// 航点/盘旋指令。// 北京坐标(示例)

寒寒豆豆软件公司的博客 326

LeetCode-409. Longest Palindrome [C++][Java]

Given a stringswhich consists of lowercase or uppercase letters, returnthe length of thelongest palindromethat can be built with those letters. Letters arecase sensitive, for example,"Aa"is not considered a palindrome here.

贫道绝缘子的博客 529

深度学习工具包 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")

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

LeetCode 409. Longest Palindrome (Java版; Easy)

welcome to my blog LeetCode 409. Longest Palindrome (Java版; Easy) 题目描述 Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built wi...

littlehaes的博客 408

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

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

leetcode java开发基础算法(Easy)

Easy 1.TwoSum(easy) /** * 利用map来存储数组中的值以及对应的index,时间复杂度为O(n),空间复杂度为O(n) * 再遍历一次map,如果map中包含有(target-key)的键,则返回这两个键的value,时间复杂度为O(n) * 总的时间复杂度为O(n),空间复杂度为O(n) * @param nums * @param target...

Bug_Solver1996的博客 440

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

leetcode oj java Longest Palindrome

一、问题描述: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "A

Xcy的博客 336

LeetCode-Longest Palindrome

LeetCode Java Longest Palindrome

坟头草一米七五 363

LeetCode 5. Longest Palindromic Substring

LeetCode 5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output: "bab" N...

个人博客 483

LeetCode笔记:409. Longest Palindrome

从一个字符串中获取字母构建最长的回文

Minecraft 1435

Leetcode 409 Longest Palindrome

Leetcode 409 Longest Palindrome class Solution { public int longestPalindrome(String s) { int[] count = new int[128]; for (char c: s.toCharArray()) count[c]++; ...

weixin_43876597的博客 138

【Leetcode】409. Longest Palindrome

题目地址: https://leetcode.com/problems/longest-palindrome/ 给定一个字符串,可以从其中挑选任意多字符,问能组成的最长回文字符串的长度。 可以先统计字符串中各个字符出现的次数,出现偶数次的全部用上,放在两边,出现奇数次的,取出最多偶数个(如果出现nnn次并且nnn是奇数,那就取n/2∗2n/2*2n/2∗2个,这里除法是计算机里的整除)。最后看一下...

数学、算法爱好者的博客 162

409. [LeetCode]Longest Palindrome

原题地址java答案:public class Solution { public boolean isSingle(int number){ // isOdd if(number%2 == 0) return false; return true; } public int chooseChar(char c){ if(c>='A

薛昭君的博客 488

【LeetCode】409. Longest Palindrome (java实现)

原题链接https://leetcode.com/problems/longest-palindrome/原题Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.T

添经地翼的博客 1191

【LeetCode】409. Longest Palindrome 解题报告(Python & C++)

【LeetCode】Longest Palindrome 解题报告标签(空格分隔): LeetCode[LeetCode]https://leetcode.com/problems/longest-palindrome/ Difficulty: Easy Question Given a string which consists of lowercase or uppercase letter

负雪明烛 2232

[双指针] leetcode 1147 Longest Chunked Palindrome Decomposition

problem:https://leetcode.com/contest/weekly-contest-148/problems/longest-chunked-palindrome-decomposition/ 周赛题。首尾两个指针,检测前后字符串是否相等,如果相等则两个指针都移动到下一个匹配位置;不相等则继续在当前位置查找匹配。 class Solution ...

ayzejx8547408的博客 158
上一篇: LeetCode算法题-Convert a Number to Hexadecimal(Java实现)
下一篇: LeetCode算法题-Fizz Buzz(Java实现)
程序员小川
博客等级 码龄10年 47粉丝 305原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值