[LeetCode]409. Longest Palindrome(最长回文)

在 Mac OS 上编译 WebRTC 教程 阅读详情

409. 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 “Aa” is not considered a palindrome here.

Note:
Assume the length of given string will not exceed 1,010.
(假设给定字符串的长度不会超过1,010。)

Example:

Input:
"abccccdd"

Output:
7

Explanation:
One longest palindrome that can be built is "dccaccd", whose length is 7.

题目大意:
给定一个由小写或大写字母组成的字符串,找到可以用这些字母构建的最长的回文长度。
这是区分大小写的,例如“Aa”在这里不被视为回文。

错误思路: 思路是错误的!!!!!!!
刚开始以为求最大回文串长度,遍历字符串,求出各个字母数量,将所有的偶数相加,最后加上最大的奇数即可

代码如下:

//错误
    int longestPalindrome(string s) {//所有偶数加上一个最大的奇数
        int tmp[123] = {0};//a~z 65-9 A~Z 97-122
        int res=0;
        for(int i=0; i<s.size(); i++){
            tmp[s[i]] += 1;
        }
        for(int m=0; m<123; m++)//将所有数量为偶数的字母数量加起来
            if(tmp[m]>0 && tmp[m]%2==0)
                res += tmp[m];
        int maxOddNumber = 0;//最大的 数量为奇数的字母 的数量
        for(int n=0; n<123; n++)//将所有数量为奇数的字母数量加起来
            if(tmp[n]>0 && tmp[n]%2==1)
                if(tmp[n]>maxOddNumber)
                    maxOddNumber = tmp[n];
        cout <<  "maxOddNumber=" << maxOddNumber << endl;
        return res+maxOddNumber;
    }

正确思路: 思路是正确的!!!!!!!

回文串除中间字母外前后对称,也就是说,除了中间的字母外,其余的字母在回文中的数量必须是偶数。

发现奇数-1就是偶数,也能算到最大回文串长度中!
最大回文串长度 = 所有的偶数 + 所有的(奇数-1) + 1(有奇数+1 ,没奇数不加)

代码如下:

#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
    //正确
    int longestPalindrome(string s) {//所有偶数+所有(大于1的奇数-1变成偶数)+1(有奇数+1 ,没奇数不加)
        int tmp[123] = {0};//a~z 65-9 A~Z 97-122
        int res=0;
        for(int i=0; i<s.size(); i++){
            tmp[s[i]] += 1;
        }
        bool a = false;//判断是否有奇数
        for(int m=0; m<123; m++){//将所有数量为偶数的字母数量加起来
            if(tmp[m]>0 && tmp[m]%2==0)
                res += tmp[m];
            if(tmp[m]>0 && tmp[m]%2==1){//所有的奇数-1变成偶数
                a = true;
                res = res + (tmp[m]-1);
            }
        }
        return a ? res+1 : res;//有奇数+1 ,没奇数不加
    }
};
int main()
{
    Solution a;
    string s;
    //cin >> s;
    s="civilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth";
    cout << a.longestPalindrome(s) << endl;//应该是983
    return 0;
}
Java SSH框架学习 阅读详情

相关推荐

基于STM32的四旋翼无人机项目(一):硬件架构与核心模块解析

本文详细解析了基于STM32的四旋翼无人机硬件架构与核心模块设计,包括主控芯片选型、姿态传感器模块、电机驱动电路及电源管理系统。通过实战经验分享,帮助开发者避免常见设计陷阱,提升无人机飞控系统的稳定性和性能。特别适合STM32开发者和无人机爱好者参考。

weixin_30919571的博客 640

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:Failed to transfer 错误码code 409

原因: 今天往公司maven私服上传jar时,发现报错,而且错误码不是400、401这种的错误码,而是409,百度中好像没用关于这个错误的,今天就记录一下。 最后,发现409的错误码是因为上传的maven私服有问题,我本地需要上传到maven私服的jar包是SNAPSHOT快照版本的,而私服是release版本的,所以就报错了,快照版本的jar包不能上传到re...

qq_35634181的博客 5983

智能车实战——极速越野组GPS与惯导融合定位导航全解析

本文深入解析了智能车极速越野组中GPS与惯导模块的融合定位导航技术。通过对比GPS的全局定位与惯导的高频姿态感知,详细阐述了如何利用MM32SPN27主控,将两者数据融合以实现精准、实时的车辆控制。内容涵盖硬件选型、软件数据处理、PID控制及系统调试等实战环节,为智能车开发者提供了一套完整的解决方案。

pz8901234的博客 1221

力扣(leetcode)第409题最长回文串(Python)

最后,我写了一篇MySQL教程,里面详细的介绍了MySQL的基本概念以及操作指令等内容,欢迎阅读!给定一个包含大写字母和小写字母的字符串 s ,返回 通过这些字母构造成的 最长的回文串。在构造过程中,请注意 区分大小写。比如 “Aa” 不能当做一个回文字符串。我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。s 只由小写 和/或 大写英文字母组成。输入:s = “abccccdd”输入:s = “aaaaaccc”输入:s = “a”

qq_58737789的博客 1002

OpenHarmony实战开发-如何实现文件分布式同步编辑

在分布式文件场景中,分布式设备管理包含了分布式设备搜索、分布式设备列表弹窗、远端设备拉起三部分。首先在分布式组网内搜索设备,然后把设备展示到分布式设备列表弹窗中,最后根据用户的选择拉起远端设备。两台设备组网的分布式场景是工作中常常需要的。这样的分布式场景有助于加快工作效率,减少工作中的冗余,本例将为大家介绍如何实现上述功能。​ (2)订阅分布式数据变化:通过this.distributedObject.on(‘status’, this.statusCallback)监听分布式数据对象的变更。

2401_82546228的博客 759

FreeSWITCH视频通话实战:关键配置文件解析与编解码优化

本文详细解析了FreeSWITCH视频通话实战中的关键配置,重点介绍了如何通过修改`conf/vars.xml`和`sip_profiles/internal.xml`文件来启用媒体代理、优化编解码器设置(如H.264和VP8),并解决常见的视频流协商与网络穿透问题,帮助用户快速实现稳定、高质量的视频通话功能。

js777的博客 264

LeetCode 409——最长回文串

1. 题目 2. 解答 我们先来看一看回文子串的规律,如果回文子串的长度为偶数,那么其中所有的每个元素都出现了偶数次;如果回文子串的长度为奇数,那么有一个元素出现了奇数次而其余每个元素都出现了偶数次。 所以我们需要做的就是遍历一遍字符串,统计每个元素出现的次数。这里只有大写字母和小写字母,我们用一个大小为 52 的数组充当散列表即可。 最后我们就可以得出偶数的元素有多少个,再看看有没有多余的一个...

seniusen的博客 352

IBM 3560M3 R5 坏盘更换记录

公司一台老旧 3650M3在日常巡查过程中发现硬盘报错

ddriv的博客 3954

【五一创作】( 字符串) 409. 最长回文串 ——【Leetcode每日一题】

409. 最长回文串 给定一个包含大写字母和小写字母的字符串 s ,返回 通过这些字母构造成的 最长的回文串 。 在构造过程中,请注意 区分大小写 。比如 "Aa" 不能当做一个回文字符串。

weixin_43412762的博客 1907

告别数据丢失焦虑:用Python手把手实现Reed-Solomon码(附完整代码)

本文详细介绍了如何使用Python实现Reed-Solomon纠错码(RS码),帮助开发者有效防止数据丢失。通过基础编解码实战、文件保护方案和高级性能优化技巧,读者可以轻松掌握这一前向纠错技术,应用于物联网、文件存储和网络传输等场景,提升数据可靠性。

weixin_42527160的博客 230

MODTRAN5.2.1安装配置

MODTRAN5.2.1安装配置

Home 4327

LeetCode 409. 最长回文串(构造最长回文判断)

最长回文串 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。 在构造过程中,请注意区分大小写。比如 “Aa” 不能当做一个回文字符串。 注意: 假设字符串的长度不会超过 1010。 示例 1: 输入: “abccccdd” 输出: 7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。 看题解得,简单题也不简单。 该题并不是寻找最长回文子串,是用给出得字符串来重新排列组合成一个最长得回文字符串。 大概意思是: 回文数必须要满足得条件是最多有一个字符.

qq_46110320的博客 2179

科研绘图系列:R语言折线图(linechart plots)

科研绘图系列:R语言折线图(linechart plots)

专注生信领域 1279

【Leetcode】409. 最长回文字符串(Longest Palindrome)

Leetcode - 409 Longest Palindrome (Easy) 题目描述:求给定字符串中的字符能够组成最长字符串的长度。 Input: "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7. public int l...

厉兵秣码 282

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

leetcode 409. Longest Palindrome 最长回文串

leetcode 409. Longest Palindrome 最长回文串 leetcode 2020年3月 每日一题打卡 题目: 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。在构造过程中,请注意区分大小写。比如 “Aa” 不能当做一个回文字符串。 注意: 假设字符串的长度不会超过 1010。 示例 1: 输入:“abccccdd” 输出:7 解释:我们可以构造...

weixin_43973433的博客 302

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

LeetCode - 409 - 最长回文串(longest-palindrome)

Create by jsliang on 2019-07-25 14:47:112019-07-25 15:33:25一 目录不折腾的前端,和咸鱼有什么区别| 目录 | ...

weixin_41806099的博客 364

深度学习工具包 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 409. Longest Palindrome 最长回文串

题目:给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。注意:假设字符串的长度不会超过 1010。示例 1:输入: "abccccdd" 输出: 7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。解题思路:计算每个字母出现的次数,获取每个字母出现的最大偶数,最后求和,...

zhangzhetaojj的博客 282

Leetcode 409. 最长回文串 409. Longest Palindrome

409. 最长回文串 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。 在构造过程中,请注意区分大小写。比如 “Aa” 不能当做一个回文字符串。 注意: 假设字符串的长度不会超过 1010。 示例 1: 输入: “abccccdd” 输出: 7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。 执行用时 : 4 ms, 在Longest Pa...

歌古道的博客 363

Java描述 LeetCode,409. Longest Palindrome 最长回文

大家好,我是河海哥,专注于后端,如果可以的话,想做一名code designer而不是普通的coder,一起见证河海哥的成长,您的评论与赞是我的最大动力,如有错误还请不吝赐教,万分感谢。 1-1:题目 Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Lett.

人在江湖 541

【LeetCode】 409. Longest Palindrome 最长回文串(Easy)(JAVA)

【LeetCode】 409. Longest Palindrome 最长回文串(Easy)(JAVA) 题目地址: https://leetcode.com/problems/longest-palindrome/ 题目描述: Given a string which consists of lowercase or uppercase letters, find the length of t...

qq_16927853的博客 250

LeetCode 409. 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 "Aa" is not con

ttshen5945的博客 517

leetcode 409. 最长回文串(Longest Palindrome)

目录 题目描述: 示例 1: 解法: 题目描述: 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。 在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。 注意: 假设字符串的长度不会超过 1010。 示例 1: 输入: ...

weixin_30483495的博客 97

LeetCode : 409. 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 “Aa” is not co...

心之所向 134

Leetcode 409. Longest Palindrome 构造最长回文串 解题报告

1 解题思想这道题并不是求字符串里最长的回文串,而是说用这些字符可以构成多长的回文串。所谓的回文串,就是要左右对称,所以除了中心的那个位置的字符可以出现奇数次以外,都要出现偶数次。如此,方式就很简单了: 1、统计所有字母的出现频率(分大小写) 2、统计只出现奇数次数字母的个数 3、如果2中结果不为0,字符串的长度减去2中的字母个数+1其中3的意思是,保留出现次数最多的那个奇数字母,剩下的需要全

MebiuW的专栏 4205

Leetcode 409.最长回文串(Longest Palindrome)

Leetcode 409.最长回文串 1 题目描述(Leetcode题目链接)   给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。在构造过程中,请注意区分大小写。比如 “Aa” 不能当做一个回文字符串。 注意:假设字符串的长度不会超过 1010。 输入: "abccccdd" 输出: 7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。...

qq_39378221的博客 253

leetcode 409 Longest Palindrome 最长回文串(简单)

思路:先统计每个字符出现的次数,再遍历统计后的字符次数,如果是偶数次,那么一定可以是回文字符串的一部分,加上该次数;如果是奇数n字,那么加上n-1次;最后判断如果出现过奇数次的字符,那么最后结果加1。...

ln_ydc的专栏 755
上一篇: [LeetCode]504. Base 7(七进制)
下一篇: [LeetCode]561. Array Partition I (数组分区 1)
whl_program
博客等级 码龄11年 101粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值