How to do it better or faster?


  • 0
    N

    My answer:

    SELECT DISTINCT(`d`.`id`) AS `id`, `d`.`date` AS `date`, `d`.`people` AS `people` 
    FROM `stadium` AS `d` 
        INNER JOIN (
            SELECT `a`.`id` AS `id`
            FROM `stadium` AS `a` 
                INNER JOIN `stadium` AS `b` 
                    ON `b`.`id` = `a`.`id` - 1 
                INNER JOIN `stadium` AS `c` 
                    ON `c`.`id` = `a`.`id` + 1 
            WHERE `a`.`people` >= 100 
                AND `b`.`people` >= 100
                AND `c`.`people` >= 100
        ) AS `t` 
            ON `t`.`id` = `d`.`id` 
                OR `t`.`id` = `d`.`id` + 1 
                OR `t`.`id` = `d`.`id` - 1;
    

    I think there must be better answers in this question, my code ran for too long(817ms)


Log in to reply
 

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