Problem List

Single Number

May 22, 2025Go array, bit manipulation, easy

Very simple O(n) solution, since I am repeatedly doing hashMap problems the pattern is becoming clear. However I have no doubt there is a better aproach since one of the tags is bit manipulation. But my main goal is completing many different types of problems for the time being.

Go Solution
func singleNumber(nums []int) int {
    hashMap := make(map[int]int)

    for _,num := range nums {
        hashMap[num]++
    }

    for _,num := range nums {
        if hashMap[num] == 1 {
            return num
        }
    }

    return -1
}
LeetCode Problem Link