We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 645e529 commit 6bbe081Copy full SHA for 6bbe081
โpalindromic-substrings/Chaedie.pyโ
@@ -0,0 +1,30 @@
1
+"""
2
+Solution:
3
+ 1) ์์ ์ ๊ธฐ์ค์ผ๋ก l,r ํฌ์ธํฐ๋ก ๋๋ ค์ฃผ๋ฉด์ ๊ฐ์ ๋ฌธ์์ด๋ฉด palindrome
4
+ ์ด๋ฅผ ํ์, ์ง์ ๊ธ์์ ๋ํด 2๋ฒ ์งํํด์ฃผ๋ฉด๋๋ค.
5
+Time: O(n^2) = O(n) * O(n/2 * 2)
6
+Space: O(1)
7
+
8
9
10
11
+class Solution:
12
+ def countSubstrings(self, s: str) -> int:
13
+ result = 0
14
+ for i in range(len(s)):
15
+ l, r = i, i
16
+ while l >= 0 and r < len(s):
17
+ if s[l] != s[r]:
18
+ break
19
+ l -= 1
20
+ r += 1
21
+ result += 1
22
23
+ l, r = i, i + 1
24
25
26
27
28
29
30
+ return result
0 commit comments