diff --git "a/2101040022/chapter_10/\344\272\214\345\210\206\346\237\245\346\211\276.cpp" "b/2101040022/chapter_10/\344\272\214\345\210\206\346\237\245\346\211\276.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..d329b714b795af05c2f8c395ed30551b1fc04f6f --- /dev/null +++ "b/2101040022/chapter_10/\344\272\214\345\210\206\346\237\245\346\211\276.cpp" @@ -0,0 +1,18 @@ +class Solution { +public: + int search(vector& nums, int target) { + int start = 0; + int end = nums.size() - 1; + while (start <= end) { + int mid = start + (end - start) / 2; + if (nums[mid] < target) { + start = mid + 1; + } else if (target < nums[mid]) { + end = mid - 1; + } else { + return mid; + } + } + return -1; + } +}; \ No newline at end of file