### leetcode 第5題回數

1.題目描述

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example:

`Input: "babad"Output: "bab"Note: "aba" is also a valid answer.`

Example:

`Input: "cbbd"Output: "bb"`

2.分析:

3.解決:

`class Solution {public:    string longestPalindrome(string s) {         if(s.length() <= 1)            return s;        size_t start = 0, len =0;        for(size_t i =0; i<s.length() && s.length() - i >len/2;)    //進行裁剪,如果當前剩余長度小於當前最長不進行    {             size_t left = i, right;            for(right = i+1; right < s.length() && s[right]== s[right-1];)    //對於重復的字符進行自增的操作            right++;            for(i = right--; left >0 && right < s.length()-1 && s[left-1] == s[right+1];)    //相等則向兩邊衍生        {                right++;                left--;            }            int clen = right - left + 1;                                    //判斷當前長度        if(clen > len)            {                len = clen;                start = left;            }        }         return s.substr(start,len);        }};`