We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Lonely Integer
Lonely Integer
+ 0 comments Extremely overengineered Swift solution:
func lonelyinteger(a: [Int]) -> Int { a.reduce(0, ^) }
+ 0 comments function lonelyinteger(a) { // Write your code here let result = 0; for (let i = 0;i< a.length;i++){ result = result ^ a[i]; } return result; }
+ 0 comments JAVA8 With stream (need stack to store a previus Item)
final Stack<Integer> stack=new Stack<>(); a.stream().sorted().filter((i)->{ if (stack.isEmpty()){stack.push(i);return false;} else if (stack.get(0).equals(i)){stack.pop();return false;} else return true; }).findFirst(); return stack.pop();
+ 0 comments JAVA
// Write your code here int res = 0; for(int i=0; i<a.size(); i++) { if(a.indexOf(a.get(i)) == a.lastIndexOf(a.get(i))) { res = a.get(i); } } return res;
+ 0 comments JAVA
// Write your code here int res = 0; for(int n : a) { res ^= n; } return res;
Load more conversations
Sort 537 Discussions, By:
Please Login in order to post a comment