{"id":23684081,"url":"https://github.com/lepharamramchiary/remove-duplicates-from-sorted-array-cpp-oop-leetcode","last_synced_at":"2026-01-06T05:30:21.246Z","repository":{"id":156031567,"uuid":"603723569","full_name":"LepharamRamchiary/Remove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode","owner":"LepharamRamchiary","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-19T11:51:21.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-29T20:33:26.390Z","etag":null,"topics":["cpp"],"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/LepharamRamchiary.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":"2023-02-19T11:47:18.000Z","updated_at":"2023-05-03T07:33:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0d3572c-5a5b-411b-817b-9bb477c45c39","html_url":"https://github.com/LepharamRamchiary/Remove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LepharamRamchiary%2FRemove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LepharamRamchiary%2FRemove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LepharamRamchiary%2FRemove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LepharamRamchiary%2FRemove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LepharamRamchiary","download_url":"https://codeload.github.com/LepharamRamchiary/Remove-Duplicates-from-Sorted-Array-Cpp-OOP-leetcode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239735869,"owners_count":19688355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cpp"],"created_at":"2024-12-29T20:33:06.222Z","updated_at":"2026-01-06T05:30:21.219Z","avatar_url":"https://github.com/LepharamRamchiary.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"**Question**:-\n\n**# Remove Duplicates from Sorted Array**\n\nGiven an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.\n\nSince it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result. It does not matter what you leave beyond the first k elements.\n\nReturn k after placing the final result in the first k slots of nums.\n\nDo not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.\n\nCustom Judge:\n\nThe judge will test your solution with the following code:\n```\nint[] nums = [...]; // Input array\nint[] expectedNums = [...]; // The expected answer with correct length\n\nint k = removeDuplicates(nums); // Calls your implementation\n\nassert k == expectedNums.length;\nfor (int i = 0; i \u003c k; i++) {\n    assert nums[i] == expectedNums[i];\n}\n```\n\nIf all assertions pass, then your solution will be accepted.\n\nExample 1:\n```\nInput: nums = [1,1,2]\nOutput: 2, nums = [1,2,_]\nExplanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.\nIt does not matter what you leave beyond the returned k (hence they are underscores).\n```\nExample 2:\n```\nInput: nums = [0,0,1,1,1,2,2,3,3,4]\nOutput: 5, nums = [0,1,2,3,4,_,_,_,_,_]\nExplanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.\nIt does not matter what you leave beyond the returned k (hence they are underscores).\n```\n\n**Solution**:-\n```c++\n#include\u003cbits/stdc++.h\u003e\n\nusing namespace std;\n\nclass Solution {\npublic:\n    int removeDuplicates(vector\u003cint\u003e\u0026 nums) {\n        int n = nums.size();\n        if (n == 0 || n == 1) {\n            return n;\n        }\n        int j = 0;\n        for (int i = 0; i \u003c n-1; i++) {\n            if (nums[i] != nums[i+1]) {\n                nums[j] = nums[i];\n                j++;\n            }\n        }\n        nums[j] = nums[n-1];\n        j++;\n        nums.resize(j);\n        return j;\n    }\n};\n\nint main() {\n    vector\u003cint\u003e nums = {1,1,2};\n    Solution sol;\n    int unique_count = sol.removeDuplicates(nums);\n    \n    cout \u003c\u003c \"Unique elements: \";\n    for (int i = 0; i \u003c unique_count; i++) {\n        cout \u003c\u003c nums[i] \u003c\u003c \" \";\n    }\n    cout \u003c\u003c endl;\n    \n    cout \u003c\u003c \"Number of unique elements: \" \u003c\u003c unique_count \u003c\u003c endl;\n    return 0;\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flepharamramchiary%2Fremove-duplicates-from-sorted-array-cpp-oop-leetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flepharamramchiary%2Fremove-duplicates-from-sorted-array-cpp-oop-leetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flepharamramchiary%2Fremove-duplicates-from-sorted-array-cpp-oop-leetcode/lists"}