+ 16
๐ Challenge: Find The Chosen One! ๐
We have an array (or list) with at least 3 elements in it. All elements are equal, except for one. Use whatever language you want to find that unique element! Some example arrays/lists (you can make your own, and as many as you want) and their respective results: [1, 1, 1, 2, 1, 1] -> 2 [2, 2, 5, 2, 2, 2, 2, 2, 2] -> 5 [0, 0, 0.55, 0, 0] -> 0.55 ["hello", "hello", "hello", "hello", "world", "hello"] -> "world" ["sololearn", 4, 4, 4, 4] -> "sololearn" Happy coding!
17 Answers
+ 12
Sorry for being late to the party! Here's my C# implementation โ
LINQ One-Linerใฐ
arr.GroupBy(o => o.ToString())
.Single(g => g.Count() == 1)
.Single()
I devoted myself to use LINQ to my fullest extent. โค Enjoy!
https://code.sololearn.com/cH3Zf78C9mJc/?ref=app
+ 12
https://code.sololearn.com/cNipRkRqHaPE/#java
My implementation in Java!
+ 7
My try in Python, and my first challenge in SL! ๐ค
https://code.sololearn.com/cL6J0YqYq3wH/?ref=app
+ 5
https://code.sololearn.com/WFCs96q31mFU/#js
+ 5
well, here mine, practicing on python, three-line style :)
https://code.sololearn.com/cu9i6Fo8UbXL/?ref=app
+ 5
https://code.sololearn.com/cUnHFGzBqJvC/?ref=app
My lazy one :P
+ 5
@$Vengat
lol
+ 5
updated.
this is a real try.
https://code.sololearn.com/cb2BqD8Rzgnu/?ref=app
+ 4
nice challenge, I will do it later...
+ 4
That's damn hardcoded
+ 4
You can make it a one-liner too
+ 3
Will do
+ 3
One line...Can also find element present p times
https://code.sololearn.com/c9Yb1Otvo5GW/?ref=app
+ 3
implementation in c++ (working except for lists/vecs with different element types... not handy in c++ keywords boost any etc...)
https://code.sololearn.com/cL1b4YaSfuU5/?ref=app
+ 3
will find it