1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00
LeetCode/go/palindromic-substrings.go
Matej Focko d2ef757754
go: allow testing
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-16 11:44:08 +02:00

29 lines
377 B
Go

package main
func checkSubstring(s string, i, j int) int {
if i < 0 || j >= len(s) {
return 0
}
count := 0
for i >= 0 && j < len(s) && s[i] == s[j] {
count += 1
i -= 1
j += 1
}
return count
}
func countSubstrings(s string) int {
count := 0
for i, _ := range s {
count += checkSubstring(s, i, i)
count += checkSubstring(s, i, i+1)
}
return count
}