Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Longest Consecutive Subsequence
class Solution { public: int longestConsecutive(vector<int>& nums) { int n=nums.size(); int i=0; unordered_set<int>s; int c=1,fi=0; for(int i=0;i<nums.size();i++) { s.insert(nums[i]); } while(i<n) { int t=nums[i]; if(s.find(t-1)!=s.end()) { i++; } else if(s.find(t-1)==s.end()) { int c=1; t=t+1; while(s.find(t)!=s.end()) { c++;t=t+1; } fi=max(fi,c); i++; } } return fi; } };
run
|
edit
|
history
|
help
0
project
Queue with Limited Size of Arrays
Hi
VecHotel
Depth of Bin tree
find first non repeating
Find the max and min number in array
Dar
ListCPP
Shortest path in binary tree