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}; + } +};