Here is another codility problem solution from the codility lessons (OddOccurrencesInArray - Find value that occurs in odd number of elements.) due to the copy rights I can't copy the content of the problem here so to view the problem description click here.
// you can also use imports, for example: // import java.util.*; // you can use System.out.println for debugging purposes, e.g. // System.out.println("this is a debug message"); // XORing any 2 similar number will give us zero //Zoring Zero with any number will give us the number class Solution { public int solution(int[] A) { // write your code in Java SE 8 int unPairedNum = A[0]; for (int i = 1; i < A.length; i++) { unPairedNum = unPairedNum ^ A[i]; } return unPairedNum; } }
No comments:
Post a Comment