From 172f0e00d721e236182d144ad40132026ddc1a4f Mon Sep 17 00:00:00 2001 From: Md Atif <64218887+Atif0604@users.noreply.github.com> Date: Tue, 5 Oct 2021 17:56:34 +0530 Subject: [PATCH 1/2] Create 704.cpp --- solutions/704.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 solutions/704.cpp diff --git a/solutions/704.cpp b/solutions/704.cpp new file mode 100644 index 0000000..b798a1e --- /dev/null +++ b/solutions/704.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +class Solution { + public: + int search(vector& nums, int target) { + int s = 0; + int e = arr.size() - 1; + while (s <= e) { + int mid = (s + e) / 2; + if (arr[mid] == target) + return mid; + else if (arr[mid] < target) + s = mid + 1; + else + e = mid - 1; + } + return -1; + } +}; From c534ef9dd7fad57b05dfd000382b2e385f44c1c0 Mon Sep 17 00:00:00 2001 From: Md Atif <64218887+Atif0604@users.noreply.github.com> Date: Wed, 6 Oct 2021 15:27:13 +0530 Subject: [PATCH 2/2] Update 704.cpp --- solutions/704.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/704.cpp b/solutions/704.cpp index b798a1e..920794b 100644 --- a/solutions/704.cpp +++ b/solutions/704.cpp @@ -5,12 +5,12 @@ class Solution { public: int search(vector& nums, int target) { int s = 0; - int e = arr.size() - 1; + int e = nums.size() - 1; while (s <= e) { int mid = (s + e) / 2; - if (arr[mid] == target) + if (nums[mid] == target) return mid; - else if (arr[mid] < target) + else if (nums[mid] < target) s = mid + 1; else e = mid - 1;