File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } s
3
+ * @return {boolean }
4
+ */
5
+
6
+ /**
7
+ * ๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๋ฌธ์
8
+ * ๋ฌธ์์ด์ ์ฒ๋ฆฌํ๋ ์๊ฐ์ ๋ฌธ์์ด์ ๊ธธ์ด์ ๋น๋กํ๋ฏ๋ก O(n)์ด๋ค.
9
+ * ๋ฌธ์์ด์ ๋ค์ง๊ธฐ ์ํด ์๋ก์ด ๋ฌธ์์ด์ ์์ฑํ๋ ์๊ฐ์ ๋ฌธ์์ด์ ๊ธธ์ด์ ๋น๋กํ๋ฏ๋ก O(n)์ด๋ค.
10
+ *
11
+ * ์๊ฐ ๋ณต์ก๋: O(n) - ๋ฌธ์์ด์ ์ฒ๋ฆฌํ๋ ์๊ฐ
12
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(n) - ๋ฌธ์์ด์ ๋ค์ง๊ธฐ ์ํด ์๋ก์ด ๋ฌธ์์ด์ ์์ฑ
13
+ *
14
+ *
15
+ * 1. ์๋ฌธ์๋ก ๋ฐ๊พธ๊ณ , ์ํ๋ฒณ๊ณผ ์ซ์๋ง ๋จ๊น (๊ณต๋ฐฑ, ํน์๋ฌธ์ ์ ๊ฑฐ)
16
+ * 2. ๋ฌธ์์ด์ ๋ค์ง๊ธฐ
17
+ * 3. ๋ค์ง์ ๋ฌธ์์ด๊ณผ ์๋ ๋ฌธ์์ด์ด ๊ฐ์์ง ๋น๊ต
18
+ * 4. ๊ฐ์ผ๋ฉด true, ๋ค๋ฅด๋ฉด false ๋ฐํ
19
+ */
20
+
21
+ var isPalindrome = function ( s ) {
22
+ // ์๋ฌธ์๋ก ๋ฐ๊พธ๊ณ , ์ํ๋ฒณ๊ณผ ์ซ์๋ง ๋จ๊น (๊ณต๋ฐฑ, ํน์๋ฌธ์ ์ ๊ฑฐ)
23
+ const cleanedStr = s . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, '' ) ;
24
+
25
+ // ๋ฌธ์์ด์ ๋ค์ง๊ธฐ
26
+ const reversedStr = cleanedStr . split ( "" ) . reverse ( ) . join ( "" ) ;
27
+
28
+ return cleanedStr === reversedStr ;
29
+ }
You canโt perform that action at this time.
0 commit comments