| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- data science
- kaggle
- 컴퓨터의 구조
- concurrency
- 파이썬
- 715. Range Module
- Decorator
- Python Code
- 43. Multiply Strings
- LeetCode
- 30. Substring with Concatenation of All Words
- Python Implementation
- Substring with Concatenation of All Words
- shiba
- Generator
- Regular Expression
- attribute
- 운영체제
- Class
- 프로그래머스
- Protocol
- 109. Convert Sorted List to Binary Search Tree
- iterator
- 밴픽
- 시바견
- 315. Count of Smaller Numbers After Self
- Convert Sorted List to Binary Search Tree
- Python
- t1
- DWG
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 |