File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 2ms
3+ * Time Complexity: O(n)
4+ *
5+ * Memory: 44.29MB
6+ * Space Complexity: O(1)
7+ *
8+ * Approach: ํฌ ํฌ์ธํฐ
9+ * 1) ๋ฌธ์์ด์ ์ ๋์์๋ถํฐ ์์ํ๋ ๋ ํฌ์ธํฐ๋ฅผ ์ค์
10+ * 2) ํฌ์ธํฐ๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฌธ์๊ฐ ์์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ํฌ์ธํฐ๋ฅผ ์ด๋
11+ */
12+ class Solution {
13+ public boolean isPalindrome (String s ) {
14+ int start = 0 ;
15+ int end = s .length ()-1 ;
16+
17+ while (start < end ) {
18+ char currLeft = s .charAt (start );
19+ char currRight = s .charAt (end );
20+
21+ if (!Character .isLetterOrDigit (currLeft )) {
22+ start ++;
23+ } else if (!Character .isLetterOrDigit (currRight )) {
24+ end --;
25+ } else {
26+ if (Character .toLowerCase (currLeft ) != Character .toLowerCase (currRight )) {
27+ return false ;
28+ }
29+
30+ start ++;
31+ end --;
32+ }
33+ }
34+
35+ return true ;
36+ }
37+ }
You canโt perform that action at this time.
0 commit comments