-
Notifications
You must be signed in to change notification settings - Fork 373
Closed
Description
Your LeetCode username
anshuman-gogate
Category of the bug
- Question
- Solution
- Language
- [. ] Missing Test Cases
Description of the bug
There is a missing test case
when nums: [1, 1, 2]
for this test case some code might give error
Code you used for Submit/Run operation
class Solution {
public:
int singleNonDuplicate(vector<int>& nums) {
if (nums.size() == 1) return nums[0];
int left = 0, right = nums.size()-1;
while (left <= right) {
int mid = left + (right-left) / 2;
int num = mid % 2 == 0 ? mid+1 : mid-1;
if (nums[mid] == nums[num]) { // we are in left part
left = mid + 1;
continue;
}
// right part
right = mid-1;
}
return nums[left];
}
};
// Two Sum
class Solution {
public:
vector twoSum(vector &a, int s) {
}
};
#### Language used for code
<!-- C++ -->
C++
#### Expected behavior
<!-- A clear and concise description of what you expected to happen in
contrast with what actually happened. -->
This should have resulted in an error
because according to the code we are trying
to access an invalid index in the array
#### Screenshots
<!-- If applicable, add screenshots to explain your issue. -->
#### Additional context
<!-- Add any other additional context about the bug. -->
Metadata
Metadata
Assignees
Labels
No labels