zoukankan      html  css  js  c++  java
  • String-680. Valid Palindrome II

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.

    Example 1:

    Input: "aba"
    Output: True
    

    Example 2:

    Input: "abca"
    Output: True
    Explanation: You could delete the character 'c'.
    

    Note:

    1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
    class Solution {
    public:
        bool validPalindrome(string s) {
            int i,j;
            int si,sj;
            int n=s.size();
            int count=0;
            int way=0;
            for(i=0,j=n-1;i<j;i++,j--){
                if(s[i]==s[j])
                    continue;
                else{
                    if(way==2){
                       return false;
                    }
                    if(way==1){
                        way++;
                        i=si;
                        j=sj;
                        j++; 
                    }
                    if(way==0){
                        way++;
                        count=1;
                        si=i;
                        sj=j;
                        i--;
                    }
                }  
            }
            return true;
        }
    };

    (判断是否回文)

  • 相关阅读:
    运算符的优先级
    运算符
    值类型与引用类型的区别
    进制转换
    Java总结第二期
    Java总结第一期
    库存管理系统
    MyBank后感
    day72
    day71
  • 原文地址:https://www.cnblogs.com/msymm/p/8248339.html
Copyright © 2011-2022 走看看