Jenifa

Leetcode 933: number of Recent Calls

May 25th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3.  
  4.  
  5. class RecentCounter
  6. {
  7. private:
  8.     std::vector<int>count;
  9.  
  10. public:
  11.     RecentCounter()
  12.     {
  13.  
  14.     }
  15.     int ping (int t)
  16.     {
  17.         int recent = 0;
  18.         count.push_back(t);
  19.  
  20.         for(size_t i = 0; i < count.size();  i++ )
  21.         {
  22.             if(t-count[i] <= 3000)
  23.             {
  24.                 recent++;
  25.             }
  26.         }
  27.         count.erase(count.begin(), count.end()-recent);
  28.  
  29.         return recent;
  30.  
  31.     }
  32. };
  33.  
  34. int main()
  35. {
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment