Skip to content

Commit d836772

Browse files
committed
palidrome
1 parent db46b97 commit d836772

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: LeetCode/.gitignore renamed to .gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### IntelliJ IDEA ###
2-
out/
2+
LeetCode/out/
33
!**/src/main/**/out/
44
!**/src/test/**/out/
55

@@ -25,6 +25,8 @@ bin/
2525
### VS Code ###
2626
.vscode/
2727
.idea/
28+
.out/
2829

2930
### Mac OS ###
30-
.DS_Store
31+
.DS_Store
32+
*.class

Diff for: LeetCode/src/valid/palidrome/ValidPalidrome.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
package valid.palidrome;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
37
public class ValidPalidrome {
48
public static void main(String[] args) {
5-
9+
String s = "A man, a plan, canal: Panama";
10+
System.out.println(isPalindrome(s));
11+
}
12+
13+
public static boolean isPalindrome(String s) {
14+
String normalized = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
15+
char[] normalizedCharArray = normalized.toCharArray();
16+
17+
List<String> reversedSequence = new ArrayList<>();
18+
19+
for (int i = normalizedCharArray.length - 1; i >= 0; i--) {
20+
reversedSequence.add(String.valueOf(normalizedCharArray[i]));
21+
}
22+
23+
char[] reversedCharArray = new char[normalizedCharArray.length];
24+
25+
26+
for (int y = 0; y < reversedCharArray.length; y++) {
27+
reversedCharArray[y] = reversedSequence.get(y).toCharArray()[0];
28+
}
29+
30+
return Arrays.equals(reversedCharArray, normalizedCharArray);
631
}
732
}

0 commit comments

Comments
 (0)