Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active April 2, 2026 17:07
Show Gist options
  • Select an option

  • Save thinkphp/075ff2461fb5dbf4508bb6a82a955769 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/075ff2461fb5dbf4508bb6a82a955769 to your computer and use it in GitHub Desktop.
find-duplicate-leetcode.java
class Solution {
public int findDuplicate(int[] nums) {
Arrays.sort(nums); //quicksort O(n log n)
for(int i = 0; i < nums.length; ++i) { //O(n)
if(nums[i] == nums[i+1]) return nums[i];
}
return -1;
//O(n log n)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment