Skip to content

Commit 00827c8

Browse files
Update 704.BinarySearch.cpp
1 parent 3c9fc03 commit 00827c8

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

704.BinarySearch.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
/// Time Submitted: 06/22/2021 00:07
1111
///
1212

13-
class Solution {
14-
public:
1513
int search(vector<int>& nums, int target) {
1614
return binary_search_ex(move(nums), target, 0);
1715
}
1816

19-
int binary_search_ex(vector<int> nums, int target, int offset) {
17+
int binary_search_ex(vector<int> &&nums, int target, int offset) {
2018
int ret = -1;
2119
int len = nums.size();
2220
int mid = len / 2;
@@ -33,10 +31,10 @@ class Solution {
3331

3432
if (target < nums[mid]) {
3533
std::vector<int> vec(nums.begin(), nums.begin() + mid);
36-
ret = binary_search_ex(vec, target, 0);
34+
ret = binary_search_ex(move(vec), target, 0);
3735
} else if (target > nums[mid]) {
3836
std::vector<int> vec(nums.begin() + mid, nums.end());
39-
ret = binary_search_ex(vec, target, mid);
37+
ret = binary_search_ex(move(vec), target, mid);
4038
} else {
4139
return mid + offset;
4240
}
@@ -54,4 +52,3 @@ class Solution {
5452

5553
return ret + offset;
5654
}
57-
};

0 commit comments

Comments
 (0)