leetcode -- 125. Valid Palindrome 【有效的回文 + 带条件的双指针】
来源:互联网 发布:淘宝品牌代理加盟 编辑:程序博客网 时间:2024/06/05 03:45
题目
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.
题意
给定一个字符串,判断它是否是一个回文序列,只考虑字母数字不考虑字符串中的其他情况。
分析及解答
public class Solution { public boolean isPalindrome(String s) {char[] array = s.toLowerCase().toCharArray();int low =0 , high =array.length -1;boolean result = true;while(low < high){boolean isLowLetter = (array[low] >= 97 && array[low] <= 122) || (array[low] >= 48 && array[low] <= 57);boolean isHighLetter = (array[high] >= 97 && array[high] <= 122) ||(array[high] >= 48 && array[high] <= 57);if(isHighLetter && isLowLetter){result = result && (array[low] == array[high]);low ++;high --;}else{if(!isHighLetter){high --;}if(!isLowLetter){low ++;}}}return result;}}
阅读全文
0 0
- leetcode -- 125. Valid Palindrome 【有效的回文 + 带条件的双指针】
- leetcode 125. Valid Palindrome-有效回文|双指针
- Valid Palindrome 检查是否是有效的回文 @LeetCode
- LeetCode | Valid Palindrome(有效的回文串)
- 【LeetCode】- Valid Palindrome(正确的回文)
- leetcode 125. Valid Palindrome 回文数的判断
- Valid Palindrome有效回文
- [C++]Valid Palindrome 有效回文
- leetcode 判断有效字符串是回文串Valid Palindrome
- LeetCode 125 Valid Palindrome(有效回文)(*)
- Valid Palindrome 合法的回文
- leetcode 125. Valid Palindrome | 回文string
- leetcode:Valid Palindrome 合法回文
- LeetCode - Valid Palindrome (判断“回文”)
- LeetCode (16) Valid Palindrome (回文)
- Valid Palindrome 简单的回文判断
- Valid Palindrome 合法的回文串
- LeetCode 125. Valid Palindrome 对撞指针(双索引)
- Unity3D学习笔记1——Unity大法好呀
- java面向对象
- Android MediaPlayer 多媒体(视频播放器)
- 导致页面顶部空白一行解决方法
- BZOJ 2049 洞穴勘测 (LCT 模板)
- leetcode -- 125. Valid Palindrome 【有效的回文 + 带条件的双指针】
- linux实时系统阵营
- Attempted relative import in non-package
- 笔记1:函数的概述与递归函数
- mybaits 更新choose标签条件Y加了单引号报错
- zoj-1094Matrix Chain Multiplication(栈来实现矩阵相乘)
- CodeForces
- Android应用层View绘制流程与源码分析
- 暑期集训之最小公倍数