nikunjsoni

853

Jul 25th, 2021
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int carFleet(int target, vector<int>& pos, vector<int>& speed) {
  4.         map<int, double> m;
  5.         for(int i = 0; i < pos.size(); i++)
  6.             m[-pos[i]] = (double)(target - pos[i]) / speed[i];
  7.         int res = 0;
  8.         double cur = 0;
  9.         for(auto it : m)
  10.             if(it.second > cur)
  11.                 cur = it.second, res++;
  12.         return res;
  13.     }
  14. };
RAW Paste Data