SHARE
TWEET

Untitled

a guest Sep 11th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vector<int> climbingLeaderboard(vector<int> scores, vector<int> alice) {
  2.     scores.push_back(-1);
  3.    
  4.     int aliceIndex = alice.size()-1;
  5.     int aliceScore = alice[aliceIndex];
  6.     int aliceRank = 1;
  7.     vector<int> aliceRanks(alice.size(), 0);
  8.     int lastScore = -1;
  9.  
  10.     int scoresIndex = 0;
  11.     while(true)
  12.     {
  13.         int score = scores[scoresIndex];
  14.         if(aliceScore >= score)
  15.         {
  16.             aliceRanks[aliceIndex] = aliceRank;
  17.  
  18.             if(aliceIndex == 0)
  19.             {
  20.                 break;
  21.             }
  22.             else
  23.             {
  24.                 aliceIndex--;
  25.                 aliceScore = alice[aliceIndex];
  26.             }
  27.         } else
  28.         {
  29.             if(score != lastScore)
  30.             {
  31.                 aliceRank++;
  32.             }
  33.             lastScore = score;
  34.             scoresIndex++;
  35.         }
  36.     }
  37.     return aliceRanks;
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top