2024/11/3 灵茶题单 滑动窗口 相向双指针
This commit is contained in:
parent
4dec1f8774
commit
47c4452ced
|
@ -0,0 +1,29 @@
|
|||
package com.cool.ling_cha_mount.sliding_windows;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/11/03/19:06
|
||||
* @Description: 125. 验证回文串
|
||||
*/
|
||||
public class Num125 {
|
||||
public boolean isPalindrome(String s) {
|
||||
StringBuilder stringBuilder=new StringBuilder();
|
||||
for(char c:s.toCharArray()){
|
||||
if(Character.isLetterOrDigit(c)){
|
||||
stringBuilder.append(c);
|
||||
}
|
||||
}
|
||||
String s1 = new String(stringBuilder);
|
||||
s1 = s1.toLowerCase();
|
||||
int right=s1.length()-1;
|
||||
int left=0;
|
||||
while(left<right){
|
||||
if(s1.charAt(left++)!=s1.charAt(right--)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue