File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * ์กฐ๊ฑด
3
+ * ๋ชจ๋ ๋๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ฐ๊ฟ์ ์ฒ๋ฆฌ
4
+ * ์์ด ๋์๋ฌธ์, ์ซ์๊ฐ ์๋ ๋ฌธ์๋ ์ ๊ฑฐ ํ ์ฒดํฌ
5
+ *
6
+ * ์์ด๋์ด
7
+ * ์ ๊ท์์ผ๋ก ๋ฌธ์์ด ์ค์ ์ซ์, ๋ฌธ์๋ง ์ถ์ถ
8
+ * ์ง์์ธ ๊ฒฝ์ฐ 123456
9
+ * 1-6, 2-5, 3-4๋ฅผ ๋น๊ต: length/2๋ฒ ๋น๊ต
10
+ * ํ์์ธ ๊ฒฝ์ฐ 1234567
11
+ * 1-7, 2-6, 3-5๋ฅผ ๋น๊ต: length/2๋ฒ ๋น๊ต
12
+ */
13
+
14
+ function isPalindrome ( s : string ) : boolean {
15
+ // TC: O(n)
16
+ // SC: O(n)
17
+ const str = s
18
+ . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, "" )
19
+ . replace ( / \s + / g, "" )
20
+ . toLocaleLowerCase ( ) ;
21
+ const len = str . length ;
22
+
23
+ // TC: O(n)
24
+ for ( let i = 0 ; i <= str . length / 2 - 1 ; i ++ ) {
25
+ if ( str [ i ] !== str [ len - i - 1 ] ) {
26
+ return false ;
27
+ }
28
+ }
29
+
30
+ return true ;
31
+ }
32
+
33
+ // TC: O(n)
34
+ // SC: O(n)
You canโt perform that action at this time.
0 commit comments