My solution using user-defined variables


  • 0
    F
    set @count = 1;
    set @prev = null;
    select distinct Logs.Num ConsecutiveNums from Logs left join
    (select @count := IF(Num=@prev,@count+1,1) counter, @prev:= Num previous, Id from Logs) temp
    on Logs.Id = temp.Id 
    where temp.counter>=3;
    

    Just want to throw in some different idea using user defined variables, which I find is very useful for many different problems


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.