Leetcode 125. Valid Palindrome
来源:互联网 发布:旧版本ios软件 编辑:程序博客网 时间:2024/06/05 02:46
/** * Character methods. * isLetter(), isDigit(), isLetterOrDigit() * First check if characters are alphanumberic, * then check if characters are equal. */ public class Solution { public boolean isPalindrome(String s) { int low = 0, high = s.length()-1; while (low < high) { while (low < high && !Character.isLetterOrDigit(s.charAt(low))) low++; while (low < high && !Character.isLetterOrDigit(s.charAt(high))) high--; // the only possibility that two letters are palindrome when they are not equal is lower and upper letters // therefore, when char is not letter its cannot be palindrome if (s.charAt(low) != s.charAt(high)) { if (!Character.isLetter(s.charAt(low)) || !Character.isLetter(s.charAt(high)) || Math.abs(s.charAt(low) - s.charAt(high)) != 32) return false; } low++; high--; } return true; } public static boolean isAlphanumeric(char c) { if (Character.isLetter(c) || Character.isDigit(c)) return true; return false; }}
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
- ue4-Network相关-组件及数据同步
- 创建 OVS 外部网络 ext_net - 每天5分钟玩转 OpenStack(144)
- 不要过度依赖JQuery(三)
- Hive 环境配置 详解
- JRebel破解及使用方法 在tomcat-maven-plugin及tomcat中的使用
- Leetcode 125. Valid Palindrome
- 1025. PAT Ranking (25)
- C语言上课笔记:第一个C程序Hello World
- word cloud install
- Nodejs 学习笔记-概括(一)
- 对数的理解
- 【t080】遗址
- 模块
- Leetcode 28. Implement strStr()