Two one line solutions O(N) time using HashSet and List in C#


  • 0
    R
        public bool ContainsDuplicate1(int[] nums) {
            return new HashSet<int>(nums).Count < nums.Length;
        }
    
        public bool ContainsDuplicate(int[] nums) {
            return nums.Distinct().ToList().Count < nums.Length;
        }
    

Log in to reply
 

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