Simple Ruby Solution, beats 100% of submissions


  • 0
    T
    def contains_nearby_duplicate(nums, k)
      seen = {}
      nums.each_with_index do |n, i|
        return true if seen[n] && i - seen[n] <= k
        seen[n] = i
      end
      return false
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.