Skip to content

Commit c16d7f6

Browse files
Create 0680-valid-palindrome-ii.java
1 parent e4338a9 commit c16d7f6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

java/0680-valid-palindrome-ii.java

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

0 commit comments

Comments
 (0)