clean & efficient 4 liner


  • 0
    B
    select avg(number) median from
    (select number, frequency from numbers order by number) sub1, 
    (select @tot := (select sum(frequency) from numbers)-1, @med1 := FLOOR(@tot/2), @med2 := CEIL(@tot/2), @freq := 0) sub2
    where (@freq := @freq + frequency)-frequency <= @med2 AND @freq-1 >= @med1
    

Log in to reply
 

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