File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -55,3 +55,38 @@ def countSubstrings(self, s: str) -> int:
5555 cnt += 1
5656
5757 return cnt
58+
59+
60+ # 25/09/08 ๋ณต์ต
61+
62+ """
63+ โ๋ชจ๋ ํ๋ฌธ์ ์ค์ฌ์์ ์ข์ฐ ๋์นญ์ด๋คโ
64+ โ ๋ฐ๋ผ์ ๋ชจ๋ ์ค์ฌ์ ์์ ์ข์ฐ๋ก ํ์ฅํ๋ฉด์ ํ๋ฌธ์ธ์ง ํ์ธํ๋ฉด
65+ โ ๋ชจ๋ ํ๋ฌธ substring์ ํ์ ๊ฐ๋ฅ!
66+
67+ - ์ค์ฌ์ ์ ๊ฐ์๋ ์ด 2n - 1๊ฐ:
68+ - ํ์ ๊ธธ์ด: center = 0 ~ n-1 (expand(i, i))
69+ - ์ง์ ๊ธธ์ด: center = 0 ~ n-1 (expand(i, i+1))
70+
71+ TC: O(N^2)
72+ SC: O(1)
73+ """
74+
75+ class Solution :
76+ def countSubstrings (self , s : str ) -> int :
77+ count = 0
78+ for center in range (len (s )):
79+ print (center )
80+ count += self .expand (s , center , center )
81+
82+ count += self .expand (s , center , center + 1 )
83+ return count
84+
85+ def expand (self , s , left , right ):
86+ count = 0
87+ # ๋ฒ์๋ฅผ ๋ฒ์ด๋์ง ์๊ณ , palindrome์ด๋ฉด ํ์ฅ
88+ while left >= 0 and right < len (s ) and s [left ] == s [right ]:
89+ count += 1
90+ left -= 1
91+ right += 1
92+ return count
You canโt perform that action at this time.
0 commit comments