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
- Discussions
Lonely Integer
Lonely Integer
Sort by
recency
|
941 Discussions
|
Please Login in order to post a comment
List< Integer> passedNumbers = new ArrayList<>(); for (int i = 0; i a.size(); i++) { if(!passedNumbers.contains(a.get(i))) { passedNumbers.add(a.get(i)); } else { passedNumbers.remove(a.get(i)); } } return passedNumbers.get(0)
JAVA
for(Integer n: a){ int frec = Collections.frequency(a, n); if(frec==1){ num=n; } } return num;
Scala Solution
My Python solution using Mathematical logic:
group the numbers find the group that has only one element first .Single gets the IGrouping second .Single gets the int from that Grouping.