首页 > 其他 > 详细

680. Valid Palindrome II

时间:2018-06-01 23:47:54      阅读:213      评论:0      收藏:0      [点我收藏+]
class Solution {
public:
    bool validPalindrome(string s) {
        int i = 0, j = s.length() - 1;
        while (i < j) {
            if (s[i] == s[j]) {
                i++;
                j--;
            }
            else {
                return helper(s, i+1, j) || helper(s, i, j-1);
            }
        }
        return true;
    }
    bool helper(const string &s, int i, int j) {
        while (i < j) {
            if (s[i] != s[j])   return false;
            i++;
            j--;
        }
        return true;
    }
};

 

680. Valid Palindrome II

原文:https://www.cnblogs.com/JTechRoad/p/9123917.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!