[LeetCode-Easy] Single Number

Golang

not good solution

func singleNumber(nums []int) int {
  if len(nums) == 1 {
    return nums[0]
  }
  c := nums[0]
  m := map[int]bool{}
  for i := 0; i < len(nums); i++ {
    if _, ok:= m[nums[i]]; !ok {
      m[nums[i]] = true
      c = nums[i]
    } else {
      delete(m, nums[i])
    }
  }
  for k := range m {
    c = k
}
  return c
}

Javascript

// TODO