Find the Duplicate Number LeetCode solution in C++
1// Please upvote if it helps2class Solution {3public:4int findDuplicate(vector<int> &nums) {5int low = 1, high = nums.size() - 1, cnt;67while (low <= high) {8int mid = low + (high - low) / 2;9cnt = 0;10// cnt number less than equal to mid11for (int n : nums) {12if (n <= mid) ++cnt;13}14// binary search on left15if (cnt <= mid)16low = mid + 1;17else18// binary search on right19high = mid - 1;20}21return low;22}23// for github repository link go to my profile.24};