From a37b148bca8ec06657aaa761ec5fee5a8f05d62e Mon Sep 17 00:00:00 2001 From: MANUL <113660278+Manul28@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:03:41 +0530 Subject: [PATCH] find_first_and_last_position.cpp --- .../find_first_and_last_position.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Leetcode Solutions/find_first_and_last_position.cpp diff --git a/Leetcode Solutions/find_first_and_last_position.cpp b/Leetcode Solutions/find_first_and_last_position.cpp new file mode 100644 index 00000000..26dd99c2 --- /dev/null +++ b/Leetcode Solutions/find_first_and_last_position.cpp @@ -0,0 +1,15 @@ +class Solution { +public: + vector searchRange(vector& nums, int target) { + int first = -1, last = -1; + for (int i = 0; i < nums.size(); ++i) { + if (nums[i] == target) { + if (first == -1) { + first = i; + } + last = i; + } + } + return {first, last}; + } +};