Skip to content

Commit

Permalink
Create: 287-Find-the-Duplicate-Number.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykhan799 authored Sep 13, 2022
1 parent f6eb981 commit e681ad6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions go/287-Find-the-Duplicate-Number.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func findDuplicate(nums []int) int {
slow, fast := nums[0], nums[nums[0]]

for slow != fast {
slow = nums[slow]
fast = nums[nums[fast]]
}

slow = 0
for slow != fast {
slow = nums[slow]
fast = nums[fast]
}
return slow
}

0 comments on commit e681ad6

Please sign in to comment.