Leetcode 125. Valid Palindrome
来源:互联网 发布:美国历史人物 知乎 编辑:程序博客网 时间:2024/05/21 10:28
Question
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.
code
/** * 常规解法 * * @param s * @return */ public boolean isPalindrome(String s) { StringBuilder res = new StringBuilder(); for (char t : s.toLowerCase().toCharArray()) { if ((t >= '0' && t <= '9') || (t >= 'a' && t <= 'z')) { res.append(t); } } return res.toString().equals(res.reverse().toString()); }
/** * 左右指针 * * @param s * @return */ public boolean isPalindromeP(String s) { if (s == null) { return false; } int len = s.length(); int left = 0; int right = len - 1; s = s.toLowerCase(); while (left < right) { if (!Character.isLetterOrDigit(s.charAt(left))) { left++; } else if (!Character.isLetterOrDigit(s.charAt(right))) { right--; } else if (s.charAt(left) != s.charAt(right)) { return false; } else { left++; right--; } } return true; }
0 0
- [LeetCode]125.Valid Palindrome
- LeetCode 125. Valid Palindrome
- [Leetcode] 125. Valid Palindrome
- 【LeetCode】125.Valid Palindrome
- [leetcode] 125.Valid Palindrome
- [leetcode] 125.Valid Palindrome
- Leetcode 125. Valid Palindrome
- 125. Valid Palindrome LeetCode
- 【LeetCode】125. Valid Palindrome
- Leetcode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode *** 125. Valid Palindrome
- 【leetcode】125. Valid Palindrome
- [leetcode] 125. Valid Palindrome
- leetcode-125. Valid Palindrome
- LeetCode-125.Valid Palindrome
- leetcode 125. Valid Palindrome
- javaScript基础
- JavaScript 笔记 - <script>标签 defer属性 (延迟脚本)
- seconds_behind_master监控复制推延的不足及pt-heartbeat改进方法
- ScrollView嵌套ListView
- 我的第一次服务器搭建
- Leetcode 125. Valid Palindrome
- Handler使用的那些事儿
- .dll动态文件
- Git新手上路,让你快速掌握Git的基本使用
- Creating a View Class 创建自定义视图
- 空格和tab键的vi 转换
- bzoj 2118: 墨墨的等式
- gdb调试应用程序
- 拉链法(链地址法)