Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Gokul Rama
Java Solution - Sorting

Gokul Rama

Dec 19, 2023

public boolean containsDuplicate(int[] nums) {     if (nums == null || nums.length == 0) {       return false;     }     // O(N*logN) - sorting     Arrays.sort(nums);     // O(N) - iteration     for (int i=1; i<nums.length; i++) {       if (nums[i-1] == nums[i]) {         return true;       }     }     return false;   }

0

0

Comments
Comments
chirag gupta
chirag guptaa year ago

we can use set and do this in o(n).

On this page

Problem Statement

Examples

Try it yourself