Skip to content

Commit ebc9304

Browse files
committed
issue #9 125-done
1 parent 1191a50 commit ebc9304

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package leetcodeEasyLevel;
2+
3+
public class _0125ValidPalindrome {
4+
public static boolean isPalindrome(String s) {
5+
//sol1. => Runtime 24ms Memory 40MB
6+
//์ •๊ทœ์‹์œผ๋กœ ์•ŒํŒŒ๋ฒณ์ด ์•„๋‹Œ ๊ฒƒ๋“ค์„ ์—†์•ค๋‹ค
7+
String s1 = s.toLowerCase().replaceAll("[^a-zA-Z0-9]", "");
8+
System.out.println(s1);
9+
10+
//๋ฐ˜์œผ๋กœ ๋‚˜๋ˆˆ๋’ค ๊ธ€์ž๊ฐ€ ์ผ์น˜ํ•˜๋Š” ์ง€ ํ™•์ธํ•œ๋‹ค.
11+
for(int i=0; i<s1.length()/2; i++){
12+
if(s1.charAt(i) != s1.charAt(s1.length()-i-1)){
13+
return false;
14+
}
15+
}
16+
return true;
17+
18+
//sol2 => Runtime 39 ms Memory 40.4 MB
19+
//one line solution
20+
//https://leetcode.com/problems/valid-palindrome/discuss/1008365/Frankenstein's-Function-One-Line-Java-Solution
21+
/*
22+
return new StringBuilder().append(s).reverse().toString()
23+
.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()
24+
.equals(s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()) ? true: false;
25+
*/
26+
}
27+
28+
public static void main(String[] args) {
29+
String s = "A man, a plan, a canal: Panama!!"; //=> t
30+
//"race a car" //=> f
31+
System.out.println(isPalindrome(s));
32+
}
33+
}

0 commit comments

Comments
ย (0)