Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Feb 10, 2024
1 parent 3ba7e8e commit 11d5bab
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions leetcode/647.PalindromicSubstrings/palindromicSubstrings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// https://leetcode.com/problems/palindromic-substrings

package main

import (
"fmt"
)

func countSubstrings(s string) int {
res := 0
n := len(s)

for k := 0; k < n*2-1; k++ {
i, j := k/2, (k+1)/2

for i >= 0 && j < n && s[i] == s[j] {
res++
i, j = i-1, j+1
}
}

return res
}

func main() {
s := "aaa"

fmt.Println(countSubstrings(s))
}

0 comments on commit 11d5bab

Please sign in to comment.