Count Distinct Element Leetcode Javascript