{"id":22513833,"url":"https://github.com/emahtab/find-the-duplicate-number","last_synced_at":"2026-02-27T00:04:29.807Z","repository":{"id":79525487,"uuid":"260289959","full_name":"eMahtab/find-the-duplicate-number","owner":"eMahtab","description":"Find the duplicate number","archived":false,"fork":false,"pushed_at":"2020-04-30T19:37:11.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T01:41:08.713Z","etag":null,"topics":["array","leetcode","problem-solving","tortoise-and-hare-algorithm"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-30T18:39:07.000Z","updated_at":"2020-04-30T19:37:13.000Z","dependencies_parsed_at":"2023-05-10T17:15:28.409Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/find-the-duplicate-number","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/find-the-duplicate-number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffind-the-duplicate-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffind-the-duplicate-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffind-the-duplicate-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffind-the-duplicate-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/find-the-duplicate-number/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffind-the-duplicate-number/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29878278,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T23:51:21.483Z","status":"ssl_error","status_checked_at":"2026-02-26T23:50:46.793Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","leetcode","problem-solving","tortoise-and-hare-algorithm"],"created_at":"2024-12-07T03:14:36.054Z","updated_at":"2026-02-27T00:04:29.792Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Find the duplicate number\n## https://leetcode.com/problems/find-the-duplicate-number\n\nGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.\n```\nExample 1:\n\nInput: [1,3,4,2,2]\nOutput: 2\n\nExample 2:\n\nInput: [3,1,3,4,2]\nOutput: 3\n```\n**Note:**\n\n1. You must not modify the array (assume the array is read only).\n2. You must use only constant, O(1) extra space.\n3. Your runtime complexity should be less than O(n2).\n4. There is only one duplicate number in the array, but it could be repeated more than once.\n\n# Implementation : O(n)\n```java\nclass Solution {\n    public int findDuplicate(int[] nums) {\n    // Find the intersection point of the two runners.\n    int tortoise = nums[0];\n    int hare = nums[0];\n    do {\n      tortoise = nums[tortoise];\n      hare = nums[nums[hare]];\n    } while (tortoise != hare);\n\n    // Find the \"entrance\" to the cycle.\n    tortoise = nums[0];\n    while (tortoise != hare) {\n      tortoise = nums[tortoise];\n      hare = nums[hare];\n    }\n\n    return tortoise;\n  }\n}\n```\n\n# References :\n1. https://leetcode.com/articles/find-the-duplicate-number\n2. https://www.youtube.com/watch?v=LUm2ABqAs1w (Why Floyd's cycle algorithm work)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ffind-the-duplicate-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Ffind-the-duplicate-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ffind-the-duplicate-number/lists"}