码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]Word Break

时间:2015-12-06 11:18:57      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

public class Solution {
    public String longestPalindrome(String s) {
        int length = s.length();
        String result = "";
        for (int i = 0; i < length; i++) {
            int left = i;
            int right = i;
            while (right + 1 < length && s.charAt(right) == s.charAt(right + 1)) {
                right ++;
            }
            while (left > 0 && right + 1 < length && s.charAt(left - 1) == s.charAt(right + 1)) {
                left --;
                right ++;
            }
            result = right - left + 1 > result.length() ? s.substring(left, right + 1) : result;
        }
        return result;
    }
}

 

[LeetCode]Word Break

标签:

原文地址:http://www.cnblogs.com/vision-love-programming/p/5023076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!