Last active
April 2, 2026 17:07
-
-
Save thinkphp/075ff2461fb5dbf4508bb6a82a955769 to your computer and use it in GitHub Desktop.
find-duplicate-leetcode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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