[leetcode刷题系列]Valid Palindrome
来源:互联网 发布:sco unix 网络配置 编辑:程序博客网 时间:2024/05/06 06:29
模拟, 也许算是所谓的two pointers
class Solution { bool isok(char c){ return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; } char getLow(char c){ if(c >= 'A' && c <= 'Z') return c - 'A' + 'a'; return c; }public: bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int left = 0, right = s.size() - 1; while(left < right){ while(left < right) if(!isok(s[left])) ++ left; else break; if(left >= right) return true; while(left < right) if(!isok(s[right])) -- right; else break; if(right <= left) return true; char leftc = getLow(s[left]); char rightc = getLow(s[right]); if(leftc != rightc) return false; ++ left; -- right; } return true; }};
- [leetcode刷题系列]Valid Palindrome
- 【Leetcode长征系列】Valid Palindrome
- LeetCode 154题:Valid Palindrome
- [LeetCode] Palindrome Number & Valid Palindrome - 回文系列问题
- leetcode 刷题之路 19 Valid Palindrome
- [leetcode刷题系列]Palindrome Number
- [leetcode刷题系列]Palindrome Partitioning
- [leetcode刷题系列]Palindrome Partitioning II
- leetcode 第125题 valid Palindrome
- Leetcode 第125题 Valid Palindrome
- LeetCode 第 125 题 (Valid Palindrome)
- [Leetcode] Valid Palindrome
- Leetcode: Valid Palindrome
- leetcode 55: Valid Palindrome
- [LeetCode] Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode - Valid Palindrome
- [leetcode]Valid Palindrome
- oracle环境变量配置
- C++examples
- poj 1191 棋盘分割
- 权限设计
- QGIS编译
- [leetcode刷题系列]Valid Palindrome
- linux curl命令
- android反编译工具 ApkDec-Release-0.1
- GridView分页的实现
- 【SQL】MYSQL远程登录权限设置
- SurfaceView简单例子
- POJ 1573 Robot Motion (模拟+不回溯的dfs 水题)
- 这段时间忙的事情、看的书和电影
- Failed to fectch URl https://dl-ssl.google.com/android/repository/addons_list.xml, reason: Connectio