Skip to content

Commit 383ab0c

Browse files
Implement ValidPalindromeII class with palindrome check
1 parent 2da7ed6 commit 383ab0c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Strings/ValidPalindromeII.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class ValidPalindromeII {
2+
public boolean validPalindrome(String s) {
3+
int i = 0;
4+
int j = s.length()-1;
5+
6+
boolean del = false;
7+
8+
while(i < j){
9+
if(s.charAt(i) == s.charAt(j)){
10+
i++;
11+
j--;
12+
}
13+
else{
14+
return palindrome(i+1, j, s) || palindrome(i, j-1, s);
15+
}
16+
}
17+
18+
return true;
19+
}
20+
21+
static boolean palindrome(int i, int j, String s){
22+
while(i<j){
23+
if(s.charAt(i) != s.charAt(j)){
24+
return false;
25+
}
26+
27+
i++;
28+
j--;
29+
}
30+
31+
return true;
32+
}
33+
}

0 commit comments

Comments
 (0)