Skip to content

Commit 4bf599c

Browse files
committed
valid-palindrome solution
1 parent 19f6205 commit 4bf599c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

valid-palindrome/sj.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.*;
2+
class Solution {
3+
public boolean isPalindrome(String s) {
4+
String words = s.toLowerCase().replaceAll("[^0-9A-Za-z]","");
5+
//System.out.println(words);
6+
Deque<Character> stack = new ArrayDeque<>();
7+
for(int i=0;i<words.length();i++){
8+
stack.push(words.charAt(i));
9+
}
10+
while(!stack.isEmpty()){
11+
for(int i=0;i<words.length();i++){
12+
if(words.charAt(i)==stack.pop()) continue;
13+
else return false;
14+
}
15+
}
16+
return true;
17+
}
18+
}

0 commit comments

Comments
 (0)