-
Notifications
You must be signed in to change notification settings - Fork 0
/
valid_palindrome.java
34 lines (31 loc) · 1.01 KB
/
valid_palindrome.java
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
28
29
30
31
32
33
34
import java.util.*;
import jdk.tools.jlink.internal.SymLinkResourcePoolEntry;
public class valid_palindrome {
static boolean is_palindrome(String s){
boolean res= true;
Stack<Character> stack = new Stack<>();
ArrayList<Character> list = new ArrayList<>();
for(char a: s.toCharArray()){
if((int)a>= 48 && (int)a<=57 || (int)Character.toUpperCase(a)>=65 && (int)Character.toUpperCase(a)<=90){
stack.push(Character.toUpperCase(a));
list.add(Character.toUpperCase(a));
}
}
for(int i=0; i<stack.size()-1; i++){
if(stack.pop() != list.get(i)){
res = false;
break;
}
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
if(is_palindrome(str)){
System.out.println("true");
}else{
System.out.println("false");
}
}
}