Skip to content

Commit 8c4b514

Browse files
committed
Create valid-palindrome-ii.go
1 parent cb1e50a commit 8c4b514

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

valid-palindrome-ii.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package leetcode_solutions_golang
2+
3+
//https://leetcode.com/problems/valid-palindrome-ii/
4+
func validPalindrome(s string) bool {
5+
left := 0
6+
right := len(s) - 1
7+
counter := 0
8+
for left <= right {
9+
if counter > 1 {
10+
break
11+
}
12+
if s[left] != s[right] {
13+
counter++
14+
right--
15+
} else {
16+
left++
17+
right--
18+
}
19+
}
20+
if counter < 2 {
21+
return true
22+
}
23+
left = 0
24+
right = len(s) - 1
25+
counter = 0
26+
for left <= right {
27+
if counter > 1 {
28+
return false
29+
}
30+
if s[left] != s[right] {
31+
counter++
32+
left++
33+
} else {
34+
left++
35+
right--
36+
}
37+
}
38+
return true
39+
}

0 commit comments

Comments
 (0)