[LeetCode]Valid Palindrome
来源:互联网 发布:javascript游戏编程 编辑:程序博客网 时间:2024/04/28 12:59
class Solution {public:bool isPalindrome(string s) {// Start typing your C/C++ solution below// DO NOT write int main() functionTransmitString(s);for (int i = 0, j = s.size()-1; i <= j; ++i, --j){if(s[i] != s[j])return false;}return true;}void TransmitString( string& str ) {//note: do not let the string move too muchint i, j;for (i = 0, j = 0; i < str.size(); ++i){if(str[i] >= '0' && str[i] <= '9'){str[j++] = str[i];}else if (str[i] >= 'a' && str[i] <= 'z'){str[j++] = str[i];}else if (str[i] >= 'A' && str[i] <= 'Z'){str[j++] = str[i]-'A'+'a';}}str = str.substr(0, j);}};
second time
class Solution {public: bool isValidChar(char c) { if('a' <= c && c <= 'z') return true; if('A' <= c && c <= 'Z') return true; if('0' <= c && c <= '9') return true; return false; } char lowerCase(char c) { if('A' <= c && c <= 'Z') return c-'A'+'a'; else return c; } bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int l = 0; int r = s.size()-1; while(l < s.size() && !isValidChar(s[l])) l++; while(r >= 0 && !isValidChar(s[r])) r--; while(l < r) { if(lowerCase(s[l]) == lowerCase(s[r])) { l++; while(l < s.size() && !isValidChar(s[l])) l++; r--; while(r >= 0 && !isValidChar(s[r])) r--; } else return false; } return true; }};
- [Leetcode] Valid Palindrome
- Leetcode: Valid Palindrome
- leetcode 55: Valid Palindrome
- [LeetCode] Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode - Valid Palindrome
- [leetcode]Valid Palindrome
- [LeetCode]Valid Palindrome
- [Leetcode]Valid Palindrome
- LeetCode-Valid Palindrome
- [leetcode] Valid Palindrome
- LeetCode 125: Valid Palindrome
- LeetCode - Valid Palindrome
- leetcode之Valid Palindrome
- LeetCode | Valid Palindrome
- [leetcode]Valid Palindrome
- 【leetcode】Valid Palindrome
- LeetCode题解:Valid Palindrome
- 提交图片如何获取是否执行成功的办法
- Path Sum
- [LeetCode]Unique Paths II
- TCP IP协议 学习 第三章 :IP协议
- [LeetCode]Valid Number
- [LeetCode]Valid Palindrome
- css3文字渐变效果。仅支持webkit内核浏览
- [HTML] HTML基础使用速记手册
- [LeetCode]Valid Parentheses
- 解决飞秋在Windows7经常卡死
- [LeetCode]Valid Sudoku
- 服务器端开发的一些建议
- [LeetCode]Validate Binary Search Tree
- Asterisk WEBRTC