Same method with different runtimes.


  • 1
    /* Beats 35% */
    SELECT  DISTINCT(l1.Num) AS ConsecutiveNums 
    FROM    Logs l1, Logs l2, Logs l3
    WHERE   l1.Num = l2.Num
        AND l2.Num = l3.Num
        AND l1.Id + 1 = l2.Id
        AND l2.Id + 1 = l3.Id
    
    /* Beats 5.8% */
    SELECT  DISTINCT(l1.Num) AS ConsecutiveNums 
    FROM    Logs l1
    WHERE   l1.Num = (
        SELECT  l2.Num
        FROM    Logs l2
        WHERE   l2.Id = l1.Id + 1
            AND l2.Num = (
                SELECT  l3.Num
                FROM    Logs l3
                WHERE   l3.Id = l2.Id + 1
                )
        )
        
    /* Time Limit Exceed. Passed 8/12 tests */
    SELECT  DISTINCT(l1.Num) AS ConsecutiveNums 
    FROM    Logs l1
    WHERE   l1.Id + 1 = (
        SELECT  l2.Id
        FROM    Logs l2
        WHERE   l2.Id + 1 = (
            SELECT  l3.Id
            FROM    Logs l3
            WHERE   l3.Num = l2.Num 
                AND l3.Num = l1.Num
                AND l3.Id = l2.Id + 1
                AND l3.Id = l1.Id + 2
            )
        )
    
    

Log in to reply
 

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