일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- t1
- 프로그래머스
- concurrency
- 715. Range Module
- kaggle
- 파이썬
- Python
- data science
- LeetCode
- 시바견
- Protocol
- DWG
- iterator
- 315. Count of Smaller Numbers After Self
- shiba
- 컴퓨터의 구조
- Generator
- Python Code
- attribute
- Python Implementation
- Decorator
- Regular Expression
- 30. Substring with Concatenation of All Words
- 운영체제
- Class
- 43. Multiply Strings
- 밴픽
- 109. Convert Sorted List to Binary Search Tree
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
Archives
- Today
- Total
Scribbling
[C++] lower_bound, upper_bound 본문
LeetCode 34. Find First and Last Position of Element in Sorted Array
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
if (nums.size() == 0) {
return {-1, -1};
}
int i = lower_bound(nums.begin(), nums.end(), target) - nums.begin();
int j = upper_bound(nums.begin(), nums.end(), target) - 1 - nums.begin();
if (i < nums.size() && nums[i] == target) {
return {i, j};
}
return {-1, -1};
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] Chapter 2: Types (0) | 2023.08.21 |
---|---|
[C++] Load Balancing (0) | 2023.08.19 |
[C++] isalnum, tolower (0) | 2023.08.18 |
[C++] LeetCode 128. Longest Consecutive Sequence (0) | 2023.08.18 |
[C++] LeetCode 238. Product of Array Except Self (0) | 2023.08.18 |