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
Count edges in a graph
list_of pair strings
OTHER - Two robots
ListCPP
MapTel2
Iviewb
nobita's candies problem
Test 13(2020)
const test
Parenthesis checker