I ran this from my local , and I got the result , but not passing leeCode

  • 0

    SELECT l1.Num AS ConsecutiveNums
    FROM Logs as l1
    INNER JOIN Logs as l2 ON l1.Num=l2.Num
    Inner join Logs as l3 On l2.Num=l3.Num
    Where l1.Id+1=l2.Id
    and l2.Id+1=l3.Id

  • 0

    My accepted solution:
    select distinct p.Num from Logs p inner join Logs p1 on p1.Id = p.Id +1 inner join Logs p2 on p2.Id = p.Id +2 where p.Num = p1.Num and p.Num = p2.Num

    I joined on Id because each Id can have only one Id+1 or Id +2. But there can be many same num in a huge table. In this case, your query will run many (useless) comparison for Id

  • 0

    Why is it not passing? Did you check the expected and actual output? I think it misses a distinct though. Imagine an input of 1,1,1,2,1,1,1 with consecutive ids. Your solution will select the 1st and then 5th row, both are ones so your resultset is 1,1.

Log in to reply

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