Skip to content

Commit c8ec385

Browse files
committed
palindromic-substrings
1 parent 61cc513 commit c8ec385

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

palindromic-substrings/chjung99.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
func countSubstrings(s string) int {
2+
ans := 0
3+
n := len(s)
4+
5+
for i := 0; i < n; i++ {
6+
for j := i+1; j <= n; j++ {
7+
if (isPalindrom(s[i:j])) {
8+
ans++
9+
}
10+
}
11+
}
12+
return ans
13+
}
14+
15+
func isPalindrom(s string) bool {
16+
var rev []byte
17+
n := len(s)
18+
for i := n-1; i >= 0; i-- {
19+
rev = append(rev, s[i])
20+
}
21+
return string(rev) == s
22+
}
23+
24+

0 commit comments

Comments
 (0)