Advertisement
nikunjsoni

853

Jul 25th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement