Skip to content

Commit a89f64c

Browse files
Create 0680-valid-palindrome-ii.go
1 parent 0cb22b5 commit a89f64c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

go/0680-valid-palindrome-ii.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
func validPalindrome(s string) bool {
2+
i := 0
3+
j := len(s) - 1
4+
5+
for i < j {
6+
if s[i] == s[j] {
7+
i += 1
8+
j -= 1
9+
} else {
10+
return validPalindromeUtil(s, i + 1, j) || validPalindromeUtil(s, i, j - 1)
11+
}
12+
}
13+
return true
14+
}
15+
16+
func validPalindromeUtil(s string, i, j int) bool {
17+
for i < j {
18+
if s[i] == s[j] {
19+
i += 1
20+
j -= 1
21+
} else {
22+
return false
23+
}
24+
}
25+
return true
26+
}

0 commit comments

Comments
 (0)