From 6f621b08b93f8ea97657eacabbe8efd6cad4c42e Mon Sep 17 00:00:00 2001 From: kalpana <154818080+Kalpana8055@users.noreply.github.com> Date: Sat, 27 Jan 2024 14:21:32 +0000 Subject: [PATCH] Day-26 q3: Find first and last position of element in sorted array #560 --- .../kalpana--cpp.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md diff --git a/Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md b/Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md new file mode 100644 index 00000000..b1a8f1aa --- /dev/null +++ b/Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md @@ -0,0 +1,16 @@ +class Solution { +public: + vector searchRange(vector& nums, int target) { + vector ans(2,-1); + if(nums.size()==0)return ans; + int t1=lower_bound(nums.begin(),nums.end(),target)-nums.begin(); + int t2=upper_bound(nums.begin(),nums.end(),target)-nums.begin(); + if(t1==t2)return ans; + cout<