From 78e09d28dbb47e96f2121390b1a0be8ad01809c2 Mon Sep 17 00:00:00 2001 From: Powfu <1875065753@qq.com> Date: Tue, 26 Dec 2023 12:34:45 +0000 Subject: [PATCH] =?UTF-8?q?add=202101040022/chapter=5F10/=E4=BA=8C?= =?UTF-8?q?=E5=88=86=E6=9F=A5=E6=89=BE.cpp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Powfu <1875065753@qq.com> --- ...14\345\210\206\346\237\245\346\211\276.cpp" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "2101040022/chapter_10/\344\272\214\345\210\206\346\237\245\346\211\276.cpp" 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 00000000..d329b714 --- /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 -- Gitee