Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Longest Consecutive Subsequence
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
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; } };
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
edit mode
|
history
|
discussion