File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ * ์ ๊ทผ ๋ฐฉ๋ฒ :
4
+ * - ๋ฌธ์์ด ์ํํ๋ฉด์ ์๋ฌธ์๋ก ๋ณ๊ฒฝํ ๋ค, ์ ๊ท์์ ์ด์ฉํด ์ํ๋ฒณ๊ณผ ์ซ์๋ง ์ถ์ถ
5
+ * - ์ถ์ถ๋ ๋ฌธ์์ ํฌ ํฌ์ธํฐ ์ฌ์ฉํด์ ์๋ค ๋ฌธ์ ๊ฐ์์ง ๋น๊ต.
6
+ * - ๋ค๋ฅด๋ฉด false ๋ฐ๋ก ๋ฆฌํดํ๊ณ , ๋๊น์ง ๊ฐ์ผ๋ฉด true ๋ฐํ
7
+ *
8
+ * ์๊ฐ๋ณต์ก๋ :
9
+ * - ๋ฌธ์์ด ๊ธธ์ด๊ฐ n์ผ ๋, O(n)
10
+ * - match๋ก ๋ฌธ์์ด ์ฒดํฌ : O(n)
11
+ * - ํฌ ํฌ์ธํฐ๋ก ์๋ค ๋ฌธ์ ๋น๊ต : O(n)
12
+ *
13
+ * ๊ณต๊ฐ๋ณต์ก๋ :
14
+ * - ์ต์
์ ๊ฒฝ์ฐ ๋ชจ๋ ๋ฌธ์๊ฐ ์ํ๋ฒณ์ด๊ฑฐ๋ ์ซ์์ธ ๊ฒฝ์ฐ ๊ธธ์ด๊ฐ n์ด ๋จ : O(n)
15
+ *
16
+ * ๋ฐฐ์ด ์ :
17
+ * - ๋ฌธ์๊ฐ ํ์ํ ๊ฒ ์๋๋๊น ๋ถํ์ํ ๋ฐฐ์ด ๋ณํ(reverse) ์ค์ด๊ธฐ
18
+ * - ๋ฌธ์์ด์ด ์กฐ๊ฑด ๋ฒ์์ ๋ถํฉํ๋์ง ์ฒดํฌํ ๋๋ ์ ๊ท์ ํ์ฉํ๊ธฐ
19
+ */
20
+
21
+ /**
22
+ * @param {string } s
23
+ * @return {boolean }
24
+ */
25
+
26
+ var isPalindrome = function ( s ) {
27
+ const alphanumericCharacters = s . toLowerCase ( ) . match ( / [ a - z 0 - 9 ] / g) || [ ] ;
28
+
29
+ let leftPointer = 0 ;
30
+ let rightPointer = alphanumericCharacters . length - 1 ;
31
+
32
+ while ( leftPointer < rightPointer ) {
33
+ if (
34
+ alphanumericCharacters [ leftPointer ] !==
35
+ alphanumericCharacters [ rightPointer ]
36
+ ) {
37
+ return false ;
38
+ }
39
+
40
+ leftPointer ++ ;
41
+ rightPointer -- ;
42
+ }
43
+
44
+ return true ;
45
+ } ;
You canโt perform that action at this time.
0 commit comments