We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84008d2 commit 6bdb8a9Copy full SHA for 6bdb8a9
longest-consecutive-sequence/Hong-Study.cpp
@@ -0,0 +1,20 @@
1
+class Solution {
2
+public:
3
+ int longestConsecutive(vector<int>& nums) {
4
+ std::set<int> sorts{nums.begin(), nums.end()};
5
+
6
+ // 개선 필요...
7
+ int maxSequence = 0, sequence = 0, i = -1;
8
+ for (const auto& num : sorts) {
9
+ if (sorts.find(num + 1) != sorts.end()) {
10
+ sequence += 1;
11
+ } else {
12
+ maxSequence = std::max(maxSequence, sequence + 1);
13
+ sequence = 0;
14
+ }
15
16
17
+ return maxSequence;
18
19
+};
20
0 commit comments