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