Skip to content

Instantly share code, notes, and snippets.

@Palakkgoyal
Created November 14, 2022 11:16
Show Gist options
  • Save Palakkgoyal/c240b83f043618a3d3ae19958cb23c5e to your computer and use it in GitHub Desktop.
Save Palakkgoyal/c240b83f043618a3d3ae19958cb23c5e to your computer and use it in GitHub Desktop.
Leetcode question of sorting
class Solution {
public boolean containsDuplicate(int[] nums) {
//first we'll sort our array
Arrays.sort(nums);
//if any number after sorting is equal to number after it, it means that number has a duplicate, hence, we return true
for(int k = 0; k < nums.length - 1; k++){
if(nums[k] == nums[k+1]){
return true;
}
}
//if you don't find any duplicate, return false
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment