You are viewing a single comment's thread. Return to all comments →
O(n) runtime. O(1) space. Uses XOR. Keep in mind:
public static int lonelyInteger(int [] array) { int val = 0; for (int num : array) { val = val ^ num; // ^ is XOR operator } return val; }
From my HackerRank Java solutions.
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
O(n) runtime. O(1) space. Uses XOR. Keep in mind:
From my HackerRank Java solutions.