The improvement to the editorial solution

  • 3
    select Id, Company, Salary from
    select e.Id, e.Salary, e.Company,  if( @prev = e.Company , @Rank := @Rank + 1, @Rank := 1) as rank, @prev := e.Company
    from Employee e , (select @Rank := 0, @prev := 0) as temp order by e.Company, e.Salary, e.Id
    ) Ranking
    select count(*) as totalcount, Company as name from Employee e2 group by e2.Company
    ) companycount
    on = Ranking.Company
    where Rank = floor((totalcount+1)/2) or Rank = floor((totalcount+2)/2)

    At this time(6/28/2017) the second one in editorial solution seems to have problem as it didn't declare the temp variable, which cause the rank to be always one, this code is the improvement to the editorial solution, which solve the problem and pass the test case.

  • 0

    @moveingsun Thanks to your improvement. I will update the editorial solution.

  • 0

    @Mr.Bin It's my pleasure, and thanks for your reply

Log in to reply

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