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