File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ class SolutionValidPalindrome {
2+
3+ public boolean isPalindrome (String s ) {
4+ // ๋๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณํ
5+ // ์๋ฌธ์์ ์ซ์๋ง ๋จ๊ธฐ๊ณ ๋ชจ๋ ์ ๊ฑฐ
6+ // ์๋ค๋ก ์ฝ์ด๋ ๊ฐ์ ๊ฒฝ์ฐ ํฐ๋ฆฐ๋๋กฌ
7+ // ์ข
๋ฅ ๋ณ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ
8+ // ์์ด ๋๋ฌธ์: ์๋ฌธ์๋ก ๋ณํ
9+ // ๊ณต๋ฐฑ: ๋ฌด์
10+ // ์๋ฌธ์, ์ซ์: ํต๊ณผ
11+ // ๊ทธ ์ธ: ๋ฌด์
12+ // ์ข
๋ฃ ์กฐ๊ฑด: lt >= rt
13+ // ์๊ฐ๋ณต์ก๋: O(N), ๊ณต๊ฐ๋ณต์ก๋: O(N)
14+ var lt = 0 ;
15+ var rt = s .length () - 1 ;
16+
17+ var input = s .toCharArray ();
18+
19+ while (lt < rt ) {
20+ // ์๋ฌธ ๋๋ ์ซ์์ผ๋๊น์ง lt++
21+ while (!Character .isLetterOrDigit (input [lt ]) && lt < input .length - 1 ) {
22+ lt ++;
23+ }
24+
25+ // ๋๋ฌธ์๋ฉด ์๋ฌธ์๋ก ๋ณํ
26+ if (Character .isUpperCase (input [lt ])) {
27+ input [lt ] = Character .toLowerCase (input [lt ]);
28+ }
29+
30+ // ์๋ฌธ ๋๋ ์ซ์์ผ๋๊น์ง rt--
31+ while (!Character .isLetterOrDigit (input [rt ]) && rt > 0 ) {
32+ rt --;
33+ }
34+
35+ // ๋๋ฌธ์๋ฉด ์๋ฌธ์๋ก ๋ณํ
36+ if (Character .isUpperCase (input [rt ])) {
37+ input [rt ] = Character .toLowerCase (input [rt ]);
38+ }
39+
40+ // lt, rt ๋ฒ์๊ฐ ๊ฒน์ณค๊ฑฐ๋ lt์ rt ๊ฐ ๋ค๋ฅด๋ฉด false ๋ฐํ
41+ if (lt < rt && input [lt ] != input [rt ]) {
42+ return false ;
43+ }
44+
45+ lt ++;
46+ rt --;
47+ }
48+
49+ return true ;
50+ }
51+ }
You canโt perform that action at this time.
0 commit comments