Skip to content

Commit

Permalink
Create 647. Palindromic Substrings
Browse files Browse the repository at this point in the history
Signed-off-by: Tahsin Tunan <[email protected]>
  • Loading branch information
tahsintunan committed Dec 28, 2022
1 parent ee7a3bc commit 8981822
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions go/0647-palindromic-substrings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
func countSubstrings(s string) int {
n := len(s)
pal := func(l, r int) int {
count := 0
for l >= 0 && r < n && s[l] == s[r] {
count++
l--
r++
}
return count
}

count := 0
for i := range s {
count += pal(i, i)
count += pal(i, i+1)
}
return count
}

0 comments on commit 8981822

Please sign in to comment.