-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (29 loc) · 766 Bytes
/
Solution.java
File metadata and controls
32 lines (29 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public boolean validPalindrome(String s) {
int i = 0,
j = s.length() - 1,
markedI = 0,
markedJ = 0;
boolean leftSkip = false,
rightSkip = false;
while (i < j) {
if (s.charAt(i) == s.charAt(j)) {
i++;
j--;
} else if (!leftSkip) {
markedI = i;
markedJ = j;
i++;
leftSkip = true;
} else if (!rightSkip) {
i = markedI;
j = markedJ;
j--;
rightSkip = true;
} else {
return false;
}
}
return true;
}
}