Using set in python


#1

from sets import *
class Solution:
# @param A : tuple of integers
# @return an integer
def longestConsecutive(self, A):
n=len(A)
s = Set()
ans=0

    for ele in A:
        
        s.add(ele) 


    for i in range(n): 

  
        if (A[i]-1) not in s: 
            j=A[i] 
            while(j in s): 
                j+=1

      
            ans=max(ans, j-A[i]) 
    return ans