LeetCode: Valid Palindrome 解题报告
2014-12-30 20:16
405 查看
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,
"A man, a plan, a canal: Panama"is a palindrome.
"race a car"is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
/* SOLUTION 2: Iterator2. */ public boolean isPalindrome(String s) { if (s == null) { return false; } int len = s.length(); boolean ret = true; int left = 0; int right = len - 1; String sNew = s.toLowerCase(); while (left < right) { // bug 1: forget a ) if (!Character.isLetterOrDigit(sNew.charAt(left))) { left++; // bug 2: Line 67: error: cannot find symbol: method isLetterOrDigital(char) } else if (!Character.isLetterOrDigit(sNew.charAt(right))) { right--; } else if (sNew.charAt(left) != sNew.charAt(right)) { return false; } else { left++; right--; } } return true; }
View Code
GITHUB:
https://github.com/yuzhangcmu/LeetCode_algorithm/blob/master/string/IsPalindrome_2014_1229.java相关文章推荐
- [leetcode] 285. Inorder Successor in BST 解题报告
- [Leetcode] 108. Convert Sorted Array to Binary Search Tree 解题报告
- [Leetcode] 82. Remove Duplicates from Sorted List II 解题报告
- [leetcode] 352. Data Stream as Disjoint Intervals 解题报告
- [Leetcode] 191. Number of 1 Bits 解题报告
- [leetcode]76. Minimum Window Substring@Java解题报告
- 【LeetCode】156.Binary Tree Upside Down(Medium)(加锁题)解题报告
- LeetCode: Next Permutation 解题报告
- leetCode解题报告之Copy List with Random Pointer
- 【LeetCode】744. Find Smallest Letter Greater Than Target 解题报告
- LeetCode 216. Combination Sum III 解题报告
- [Leetcode] 313. Super Ugly Number 解题报告
- [Leetcode] 319. Bulb Switcher 解题报告
- [leetcode] 163. Missing Ranges 解题报告
- [Leetcode] 119. Pascal's Triangle II 解题报告
- 【LeetCode】 Add Digits 解题报告
- leetcode 40. Combination Sum II 解题报告
- LeetCode解题报告--Search Insert Position
- Leetcode: LRU Cache 解题报告
- [LeetCode]Nth Highest Salary,解题报告