亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

[Leetcode]Longest Palindrome

beita / 1389人閱讀

摘要:解題思路我們發(fā)現(xiàn)結(jié)果其實就是字符的偶數(shù)個數(shù)是否有單一的字符,如果有就加把單一字符放在回文中間,如果沒有就加字母區(qū)分大小寫,代碼

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.

Example:

Input:
"abccccdd"

Output:
7

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

解題思路

我們發(fā)現(xiàn)結(jié)果其實就是字符的偶數(shù)個數(shù)+是否有單一的字符,如果有就加1(把單一字符放在回文中間),如果沒有就加0;
字母區(qū)分大小寫,int[] map=new int["z"-"A"+1];
2.代碼

public class Solution {
    public int longestPalindrome(String s) {
        if(s.length()==0||s==null) return 0;
        int[] map=new int["z"-"A"+1];
        int count=0;
        int hasOdd=0;
        for(int i=0;i           
               
                                           
                       
                 

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/69828.html

相關文章

  • leetcode409.Longest Palindrome

    摘要:題目要求輸入一個字符串,計算用這個字符串中的值構(gòu)成一個最長回數(shù)的長度是多少。直觀來看,我們立刻就能想到統(tǒng)計字符串中每個字符出現(xiàn)的次數(shù),如果該字符出現(xiàn)次數(shù)為偶數(shù),則字符一定存在于回數(shù)中。這個細節(jié)需要注意。 題目要求 Given a string which consists of lowercase or uppercase letters, find the length of the...

    linkin 評論0 收藏0
  • [LintCode/LeetCode] Longest Palindrome Substring

    摘要:是左閉右開區(qū)間,所以要。,要理解是和之間只有一個元素。循環(huán)每次的時候,都要更新子串更大的情況。補一種中點延展的方法循環(huán)字符串的每個字符,以該字符為中心,若兩邊為回文,則向兩邊繼續(xù)延展。循環(huán)返回長度最長的回文串即可。 Problem Given a string S, find the longest palindromic substring in S. You may assume ...

    AaronYuan 評論0 收藏0
  • leetcode部分題目答案之JavaScript版

    摘要:自己沒事刷的一些的題目,若有更好的解法,希望能夠一起探討項目地址 自己沒事刷的一些LeetCode的題目,若有更好的解法,希望能夠一起探討 Number Problem Solution Difficulty 204 Count Primes JavaScript Easy 202 Happy Number JavaScript Easy 190 Reverse Bi...

    alphahans 評論0 收藏0
  • 前端 | 每天一個 LeetCode

    摘要:在線網(wǎng)站地址我的微信公眾號完整題目列表從年月日起,每天更新一題,順序從易到難,目前已更新個題。這是項目地址歡迎一起交流學習。 這篇文章記錄我練習的 LeetCode 題目,語言 JavaScript。 在線網(wǎng)站:https://cattle.w3fun.com GitHub 地址:https://github.com/swpuLeo/ca...我的微信公眾號: showImg(htt...

    張漢慶 評論0 收藏0
  • LeetCode 攻略 - 2019 年 7 月下半月匯總(100 題攻略)

    摘要:月下半旬攻略道題,目前已攻略題。目前簡單難度攻略已經(jīng)到題,所以后面會調(diào)整自己,在刷算法與數(shù)據(jù)結(jié)構(gòu)的同時,攻略中等難度的題目。 Create by jsliang on 2019-07-30 16:15:37 Recently revised in 2019-07-30 17:04:20 7 月下半旬攻略 45 道題,目前已攻略 100 題。 一 目錄 不折騰的前端,和咸魚有什么區(qū)別...

    tain335 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<