From 8b989002b31b1559cc581d8bc9f5951dabe0cab7 Mon Sep 17 00:00:00 2001 From: Sovan Roy <110086883+SovanRoy10@users.noreply.github.com> Date: Thu, 19 Oct 2023 06:43:08 +0530 Subject: [PATCH 1/4] added one solution in cpp --- C++/SearchInRotatedSortedArray.cpp | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 C++/SearchInRotatedSortedArray.cpp diff --git a/C++/SearchInRotatedSortedArray.cpp b/C++/SearchInRotatedSortedArray.cpp new file mode 100644 index 00000000..d3daebd3 --- /dev/null +++ b/C++/SearchInRotatedSortedArray.cpp @@ -0,0 +1,51 @@ +// leetcode question number : 33 +//question level : medium + +/* + Github username: SovanRoy10 + Aim: My aim is to give the correct solution of search in rotated sorted array (leetcode question no 33) + Date: 19 October, 2023 +*/ + +// solution : +class Solution +{ + public: + int pivot(vector &nums) + { + int s = 0, l = nums.size() - 1; + while (s < l) + { + int mid = s + (l - s) / 2; + if (nums[mid] < nums[0]) + l = mid; + else + s = mid + 1; + } + return l; + } + int binary_search(vector &nums, int s, int l, int target) + { + while (s <= l) + { + int mid = s + (l - s) / 2; + if (nums[mid] == target) + return mid; + else if (nums[mid] < target) + s = mid + 1; + else + l = mid - 1; + } + return -1; + } + int search(vector &nums, int target) + { + int pivot_index = pivot(nums); + int ans = binary_search(nums, 0, pivot_index - 1, target); + if (ans != -1) + return ans; + return binary_search(nums, pivot_index, nums.size() - 1, target); + } +}; + +// video solution : https://www.youtube.com/watch?v=iXLMMbdjeNM \ No newline at end of file From 671c83f2a0d0beef09aa42217f1e56f904e4b398 Mon Sep 17 00:00:00 2001 From: Sovan Roy <110086883+SovanRoy10@users.noreply.github.com> Date: Thu, 19 Oct 2023 06:43:30 +0530 Subject: [PATCH 2/4] edited the CONTRIBUTORS.md --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f3226313..f9a9a9ed 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -65,7 +65,7 @@ | Tharindu Sooriyaarchchi | E-Mail | | Samriddh Prasad | Samriddh Prasad | E-Mail | | Edgar Gonzalez | Edgar Gonzalez | E-Mail | - +| Sovan Roy | Sovan Roy | E-Mail From 766317e68fa3940e30db1398f39f1269e4ef13e3 Mon Sep 17 00:00:00 2001 From: Sovan Roy <110086883+SovanRoy10@users.noreply.github.com> Date: Thu, 19 Oct 2023 06:46:18 +0530 Subject: [PATCH 3/4] added one solution in cpp --- C++/SearchInRotatedSortedArray.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/C++/SearchInRotatedSortedArray.cpp b/C++/SearchInRotatedSortedArray.cpp index d3daebd3..eaa4bd5a 100644 --- a/C++/SearchInRotatedSortedArray.cpp +++ b/C++/SearchInRotatedSortedArray.cpp @@ -5,6 +5,7 @@ Github username: SovanRoy10 Aim: My aim is to give the correct solution of search in rotated sorted array (leetcode question no 33) Date: 19 October, 2023 + */ // solution : From 38ee87c7e75f0be15d9cdb672704c9e817bf1986 Mon Sep 17 00:00:00 2001 From: Sovan Roy <110086883+SovanRoy10@users.noreply.github.com> Date: Thu, 19 Oct 2023 06:46:41 +0530 Subject: [PATCH 4/4] edited the CONTRIBUTORS.md --- CONTRIBUTORS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f9a9a9ed..2810d6e5 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -64,8 +64,9 @@ | Sneha Chaudhary | Sneha Chaudhary | E-Mail | | Tharindu Sooriyaarchchi | E-Mail | | Samriddh Prasad | Samriddh Prasad | E-Mail | -| Edgar Gonzalez | Edgar Gonzalez | E-Mail | | Sovan Roy | Sovan Roy | E-Mail +| Edgar Gonzalez | Edgar Gonzalez | E-Mail | +