File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Runtime: 1 ms(Beats: 100.00 %)
3
+ Time Complexity: O(n)
4
+
5
+ Memory: 43.00 MB(Beats: 64.54 %)
6
+ Space Complexity: O(1)
7
+ ... ๋ฌธ์ ์์ ์ฃผ์ด์ง String s๋ space complexity ๊ณ์ฐ์์ ์ ์ธํ๊ณ , ์ ๊ฐ ์ถ๊ฐํ ๋ณ์์ ๋ํด์๋ง ๊ณ์ฐํ๋ฉด ๋ ๊น์?
8
+ */
9
+
10
+ class Solution {
11
+ public boolean isPalindrome (String s ) {
12
+ for (int i = 0 , j = s .length () - 1 ; i < j ; i ++, j --) {
13
+ char a = s .charAt (i );
14
+ while (a < '0' || (a > '9' && a < 'A' ) || (a > 'Z' && a < 'a' ) || a > 'z' ) {
15
+ a = s .charAt (++i );
16
+ if (i >= j ) {
17
+ return true ;
18
+ }
19
+ }
20
+ if (a <= 'Z' ) {
21
+ a += ('a' - 'A' );
22
+ }
23
+
24
+ char b = s .charAt (j );
25
+ while (b < '0' || (b > '9' && b < 'A' ) || (b > 'Z' && b < 'a' ) || b > 'z' ) {
26
+ b = s .charAt (--j );
27
+ if (i >= j ) {
28
+ return true ;
29
+ }
30
+ }
31
+ if (b <= 'Z' ) {
32
+ b += ('a' - 'A' );
33
+ }
34
+
35
+ if (a != b ) {
36
+ return false ;
37
+ }
38
+ }
39
+ return true ;
40
+ }
41
+ }
You canโt perform that action at this time.
0 commit comments