File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,29 @@ class Solution {
8
8
// ์๊ฐ๋ณต์ก๋ : O(n)
9
9
// ๊ณต๊ฐ๋ณต์ก๋ : O(n)
10
10
public boolean isPalindrome (String s ) {
11
+ // replaceAll(...): ๋ฌธ์์ด ์ ์ฒด๋ฅผ ํ ๋ฒ ์ํ โ O(n)
12
+ // trim(): ๊ณต๋ฐฑ์ ์์ชฝ ๋์์๋ง ํ์ โ O(n) ์ด๋ผ๊ณ ๋ณด์ง๋ง ๋ณดํต ๋ฌด์ ๊ฐ๋ฅํ ์์ค
13
+ // toLowerCase(): ๋ชจ๋ ๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ฐ๊ฟ โ O(n)
14
+ String cleanString = s .replaceAll ("[^a-zA-Z0-9]" , "" ).trim ().toLowerCase ();
15
+
16
+ int left = 0 ;
17
+ int right = cleanString .length () - 1 ;
18
+
19
+ //O(n)
20
+ while (left < right ) {
21
+ if (cleanString .charAt (left ) != cleanString .charAt (right )) {
22
+ return false ;
23
+ }
24
+ left ++;
25
+ right --;
26
+ }
27
+ return true ;
11
28
12
29
}
13
30
}
14
31
15
32
//-------------------------------------------------------------------------------------------------------------
16
33
// Java ๋ฌธ๋ฒ ํผ๋๋ฐฑ
17
- //
34
+ // 1) char[] ๋๋ฌธ์ Char ๊ฐ ์๋๊ณ ์์คใด์
35
+ // 2) ~.equals๋ char์์ ์ ๊ณต๋์ง ์์
18
36
//-------------------------------------------------------------------------------------------------------------
You canโt perform that action at this time.
0 commit comments