The Single Number Problem

I was tackling a few problems from LeetCode and stumbled upon a problem that resonated with me. The Single Number problem, this particular question requires me to single out the non-repeating digit. My first initial thought process was to sort the numbers in the array. Once completed I created a condition that checks if the integer repeats before it and after it then return it. Which worked out in the long run.


Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. check out the example below.

Let's Break it Down

I started by creating a variable that sorts the number for example.

I looped through the sorted numbers in the array then proceeded to add the conditional statement. The statement states if the current number does not equal the value or type after, and before it. Here is a better look below.

If the condition checked out I would simply return that number that does not repeat. here is a better look below.

here is a full look at the problem.

Thanks for reading, till next time coders.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store