An AC solution using one veriable


  • 0
    M

    This solution use an extra variable to find the begin of each consecutive row, then check each row in the table to see if within three rows there is a row marked as the beginning of a consecutive row.

    select distinct s.id, s.date, s.people from stadium s, (select s1.id, s1.date, s1.people, @flag:=1 as flag from stadium s1, (select @flag := 0 ) temp where s1.people >= 100 and (select people from stadium s2 where s2.id = s1.id + 1)>=100 and (select people from stadium s3 where s3.id = s1.id + 2)>=100 ) temp2  where (flag = 1 and (temp2.id = s.id - 1 or temp2.id = s.id -2 or temp2.id = s.id))
    

Log in to reply
 

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