Leetcode 933 Number of Recent Calls
Write a class RecentCounter
to count recent requests.
It has only one method: ping(int t)
, where t represents some time in milliseconds.
Return the number of ping
s that have been made from 3000 milliseconds ago until now.
Any ping with time in [t - 3000, t]
will count, including the current ping.
It is guaranteed that every call to ping
uses a strictly larger value of t
than before.
Example 1:
Input: inputs = ["RecentCounter","ping","ping","ping","ping"], inputs = [[],[1],[100],[3001],[3002]] Output: [null,1,2,3,3]
這個題的意思是找到在給定數字中符合條件的部分。
1)
class RecentCounter {
PriorityQueue<Integer> queue = new PriorityQueue<>();
public RecentCounter() {
}
public int ping(int t) {
queue.add(t);
while(queue.peek() < t - 3000){
queue.poll();
}
return queue.size();
}
}
/**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter obj = new RecentCounter();
* int param_1 = obj.ping(t);
*/
2)
class RecentCounter {
set<int> history;
public:
int ping(int t) {
history.insert( t );
return distance( history.lower_bound( t - 3000 ), history.end() );
}
};
相關文章
- LeetCode之Number of Recent Calls(Kotlin)LeetCodeKotlin
- Leetcode Number of islandsLeetCode
- [LeetCode] Third Maximum NumberLeetCode
- [LeetCode] Find the Duplicate NumberLeetCode
- Leetcode 9 Palindrome NumberLeetCode
- Leetcode 447 Number of BoomerangsLeetCodeOOM
- [LeetCode] 9. Palindrome NumberLeetCode
- LeetCode之Fibonacci Number(Kotlin)LeetCodeKotlin
- Leetcode 611 javascript Valid Triangle NumberLeetCodeJavaScript
- [LeetCode] 248. Strobogrammatic Number IIILeetCode
- [LeetCode] 191. Number of 1 BitsLeetCode
- [LeetCode] 305. Number of Islands IILeetCode
- Leetcode 17 Letter Combinations of a Phone NumberLeetCode
- Leetcode 137. Single Number IILeetCode
- 【Leetcode】1395. Count Number of TeamsLeetCode
- LeetCode Palindrome Number(009)解法總結LeetCode
- Leetcode – 017. Letter Combinations of a Phone NumberLeetCode
- [LeetCode] 3238. Find the Number of Winning PlayersLeetCode
- [LeetCode] 2684. Maximum Number of Moves in a GridLeetCode
- Leetcode 202 Happy Number Javascript 解決方案LeetCodeAPPJavaScript
- [LeetCode] 2406. Divide Intervals Into Minimum Number of GroupsLeetCodeIDE
- LeetCode - 解題筆記 - 8 - Palindrome NumberLeetCode筆記
- LeetCode Letter Combinations of a Phone Number(017)解法總結LeetCode
- Leetcode 之 PHP 解析 (260. Single Number III)LeetCodePHP
- leetcode學習筆記09 palindrome-numberLeetCode筆記
- [Javascript] Proper Tail CallsJavaScriptAI
- CF933-Div3
- Traceback (most recent call last):AST
- LeetCode演算法題-Number of Boomerangs(Java實現)LeetCode演算法OOMJava
- LeetCode65. Valid Number — 判斷合法數字LeetCode
- [LeetCode] 1953. Maximum Number of Weeks for Which You Can WorkLeetCode
- [LeetCode] 3226. Number of Bit Changes to Make Two Integers EqualLeetCode
- LeetCode 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance??LeetCode
- LeetCode 452. Minimum Number of Arrows to Burst Balloons Sort/MediumLeetCode
- Unity SRP 02 Draw CallsUnity
- Codeforces Round 933 (Div. 3)
- [LeetCode] 3239. Minimum Number of Flips to Make Binary Grid Palindromic ILeetCode
- Leetcode 1365. How Many Numbers Are Smaller Than the Current Number (cpp)LeetCode