[LeetCode-Easy] Contains Duplicate

Golang

sorting concept, and check next value if equal

func containsDuplicate(nums []int) bool {
    sort.Ints(nums)
    for i:= 0; i <len(nums) - 1;i++{
        if nums[i] == nums[i + 1] {
            return true
        }
    }
    return false
}

Javascript

using hash table concept

/**
 * @param {number[]} nums
 * @return {boolean}
 */
var containsDuplicate = function(nums) {
    let hash = {}
    
    for(let i in nums){
        if(hash[nums[i]]){
           return true
           } else {
               hash[nums[i]] = true
           }
    }
  return false
};