-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLt125.java
More file actions
27 lines (24 loc) · 775 Bytes
/
Lt125.java
File metadata and controls
27 lines (24 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package string;
class Lt125 {
public boolean isPalindrome(String s) {
// 인덱싱을 위한 변수
int left = 0;
int right = s.length() - 1;
while (left < right) {
// isLetterOrDigit() -> 특수문자 거르기
if (!Character.isLetterOrDigit(s.charAt(left))) {
left++;
} else if (!Character.isLetterOrDigit(s.charAt(right))) {
right--;
// toLowerCase() -> 대소문자 상관 x
} else {
if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
return false;
}
left++;
right--;
}
}
return true;
}
}