561ms,fast,easy to be modified for other similar questions


  • 0
    B

    SELECT obj.Score,
    @tempRank := CASE
    WHEN (@Rank := @tempRank + 1) && @lastScore = obj.Score THEN @tempRank
    WHEN ((@lastScore := obj.Score)|| 1) THEN @Rank
    END
    AS Rank FROM Scores obj ,
    ( SELECT @Rank := 0 ,@lastScore := -1 ,@tempRank := 0 ) r
    order by obj.Score desc


Log in to reply
 

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