-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongestConsecutive.cpp
More file actions
54 lines (47 loc) · 1.06 KB
/
longestConsecutive.cpp
File metadata and controls
54 lines (47 loc) · 1.06 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<vector>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
class Solution
{
public:
int longestConsecutive(vector<int> &nums)
{
//计数
int count = 0;
set<int> NoRepeatElemArr;
vector<int> result;
//去除相同元素
for(int i = 0;i < nums.size();i++)
{
//防止出现相同元素
if(NoRepeatElemArr.find(nums[i]) == NoRepeatElemArr.end())
{
NoRepeatElemArr.insert(nums[i]);
result.push_back(nums[i]);
}
}
//result便没有了重复元素
for(int i = 0;i < result.size();i++)
{
for(int j = i + 1;j < result.size();j++)
{
if(result[j] - result[i] == 1)
{
count++;
}
else
{
continue;
}
}
}
return count;
}
};
int main()
{
string a = "😎";
printf("%s",a.c_str());
}