Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.Scanner;
- public class Palindrom {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- LinkedList <Integer> lista = new LinkedList<>();
- Scanner sc = new Scanner(System.in);
- int palin = 0;
- String n = sc.nextLine();
- String l = sc.nextLine();
- String[] a = l.split(" ");
- int brojac = 0;
- for(int i = 0 ; i<Integer.parseInt(n) ; i++)
- {
- lista.add(Integer.parseInt(a[i]));
- }
- if(lista.size() == 1)
- {
- palin = 1;
- }
- else
- {
- while(brojac < lista.size()/2)
- {
- if(lista.get(brojac) == lista.get(lista.size()-1-brojac))
- {
- palin = 1;
- }
- else
- {
- palin = -1;
- break;
- }
- brojac++;
- }
- }
- System.out.print(palin);
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement