You are viewing a single comment's thread. Return to all comments →
Java Solution O(N)
if(total sum = even number) then print 0 else total sum is an odd number. We know that sum of two odd numbers is always even num Since the total sum is odd, the number of odd numbers is definetely odd, deleting one of the odd numbers would result in an even sum. If we have only one number which is odd, then print -1 Simple Number Theory
Scanner in = new Scanner(System.in); int n = in.nextInt(); int sum=0; for(int i = 0; i < n; i++){ sum += in.nextInt(); } System.out.println((sum%2==0)?0:(n==1)?-1:1);
Seems like cookies are disabled on this browser, please enable them to open this website
Parity Game
You are viewing a single comment's thread. Return to all comments →
Java Solution O(N)