680. 验证回文字符串 Ⅱ

Leetcode 680. 验证回文字符串 Ⅱ_职场和发展

Leetcode 680. 验证回文字符串 Ⅱ_回文串_02

 代码:

class Solution {
public:
//判断s【low,....high】是否是回文串
    bool judge(string s,int low,int high)
    {
        while(low<=high)
        {
            if(s[low]!=s[high])
            {
                return false;
            }
            low++;
            high--;
        }
        return true;
    }

    bool validPalindrome(string s) {
int l=0;
int r=s.size()-1;
while(l<r)
{
    if(s[l]==s[r])
    {
        l++;
        r--;
    }
//如果不是回文串,判断s[l+1,...r]或s[l,....r-1]是不是回文串
    else
    return judge(s,l+1,r)||judge(s,l,r-1);
}
return true;
    }
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.