| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- data science
- Protocol
- attribute
- 315. Count of Smaller Numbers After Self
- Regular Expression
- 30. Substring with Concatenation of All Words
- Python Implementation
- kaggle
- Decorator
- concurrency
- 운영체제
- 시바견
- 109. Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- Class
- Convert Sorted List to Binary Search Tree
- Python
- 프로그래머스
- shiba
- t1
- 밴픽
- 컴퓨터의 구조
- DWG
- Generator
- 파이썬
- Substring with Concatenation of All Words
- LeetCode
- iterator
- Python Code
- 715. Range Module
Archives
- Today
- Total
Scribbling
[C++] LeetCode 128. Longest Consecutive Sequence 본문
https://leetcode.com/problems/longest-consecutive-sequence/
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
int ret = 0;
unordered_set<int> num_set(nums.begin(), nums.end());
for (int num : nums) {
// not found
if (num_set.find(num - 1) == num_set.end()) {
int cnt = 0;
while (num_set.find(num) != num_set.end()) {
num += 1;
cnt += 1;
}
ret = max(ret, cnt);
}
}
return ret;
}
};'Computer Science > C++' 카테고리의 다른 글
| [C++] lower_bound, upper_bound (0) | 2023.08.18 |
|---|---|
| [C++] isalnum, tolower (0) | 2023.08.18 |
| [C++] LeetCode 238. Product of Array Except Self (0) | 2023.08.18 |
| [C++] priority queue (vector<int>) with comparator (0) | 2023.08.18 |
| [C++] 49. Group Anagrams (0) | 2023.08.18 |