import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Stack; class ListNode { public int val; public ListNode next; public ListNode(int val) { this.val = val; this.next = null; } } public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); String[] strList = br.readLine().trim().split(" "); ListNode head = new ListNode(Integer.parseInt(strList[0])); ListNode cur = head; for(int i = 1; i < n; i++){ cur.next = new ListNode(Integer.parseInt(strList[i])); cur = cur.next; } System.out.println(isPalindrome(head)); } private static boolean isPalindrome(ListNode head) { Stack<Integer> stack = new Stack<>(); ListNode cur = head; while(cur != null){ stack.push(cur.val); cur = cur.next; } cur = head; while(cur != null){ if(cur.val != stack.pop()) return false; cur = cur.next; } return true; } }
import java.io.*; public class Main { public static void main(String[] args)throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br.readLine(); String[] s=br.readLine().split(" "); int n=s.length; int mid=n/2; boolean res=true; for(int i=0;i<mid;i++){ if(s[i].equals(s[s.length-1-i])){ }else{ res=false; break; } } System.out.println(res); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] arr = new int[n]; for (int i = 0; i < arr.length; i++) { arr[i] = scan.nextInt(); } int L = 0; int R = arr.length -1; while(L < R) { if(arr[L] != arr[R]) { System.out.println(false); return; } L++; R--; } System.out.println(true); } }