/
DeC2018
/
0034
Обзор
Документация
Войти
/
DeC2018
/
0034
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
main.cpp
40 строк
1 KB
Den
create main.cpp
13 янв 2025, 22:06
13 янв 2025, 22:06
9ecd26b
Код
Авторство
О чём код?
#include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { const int l = lower_bound(begin(nums), end(nums), target) - begin(nums); if (l == nums.size() || nums[l] != target) return {-1, -1}; const int r = upper_bound(begin(nums), end(nums), target) - begin(nums) - 1; return {l, r}; } }; int main() { Solution solution; vector<int> nums1 = {5, 7, 7, 8, 8, 10}; int target1 = 8; cout << "Input: nums = [5,7,7,8,8,10], target = 8" << endl; vector<int> result1 = solution.searchRange(nums1, target1); cout << "Output: [" << result1[0] << "," << result1[1] << "]" << endl; vector<int> nums2 = {5, 7, 7, 8, 8, 10}; int target2 = 6; cout << "Input: nums = [5,7,7,8,8,10], target = 6" << endl; vector<int> result2 = solution.searchRange(nums2, target2); cout << "Output: [" << result2[0] << "," << result2[1] << "]" << endl; vector<int> nums3 = {}; int target3 = 0; cout << "Input: nums = [], target = 0" << endl; vector<int> result3 = solution.searchRange(nums3, target3); cout << "Output: [" << result3[0] << "," << result3[1] << "]" << endl; return 0; }