标签:private 解法 ali code string -- length lse style
class Solution { public: bool validPalindrome(string s) { int len = s.length(); if (len <= 2) return true; return judge(s, 0, len - 1, 1); } private: bool judge(string s, int l, int r, int cnt) { while (l <= r - 1) { if (s[l] != s[r]) { if (cnt <= 0) return false; return judge(s, l + 1, r, cnt - 1) || judge(s, l, r - 1, cnt - 1); } l++; r--; } return true; } };
参考网上的实现,递归解法。
标签:private 解法 ali code string -- length lse style
原文地址:https://www.cnblogs.com/asenyang/p/9735078.html