109th LeetCode Weekly Contest 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]
Note:
- Each test case will have at most
10000
calls toping
. - Each test case will call
ping
with strictly increasing values oft
. - Each call to ping will have
1 <= t <= 10^9
.
就是说有一个数组,里面的每一个数字-3000得到的结果,在数组里面>=这个结果的有多少个
class RecentCounter {
public:
int x = ;
int num[];
int pre = ;
//int y;
RecentCounter() { } int ping(int t) {
int result = ;
num[pre] = t;
pre ++;
x = t - ;
for(int i = ; i<pre; i++){
if(num[i]>=x){
result++;
}
}
return result;
}
};
/**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter* obj = new RecentCounter();
* int param_1 = obj->ping(t);
*/
109th LeetCode Weekly Contest Number of Recent Calls的更多相关文章
- 【LeetCode】933. Number of Recent Calls 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 队列 相似题目 参考资料 日期 题目地址: ...
- 109th LeetCode Weekly Contest Knight Dialer
A chess knight can move as indicated in the chess diagram below: . This time, we place o ...
- 74th LeetCode Weekly Contest Number of Subarrays with Bounded Maximum
We are given an array A of positive integers, and two positive integers L and R (L <= R). Return ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
- LeetCode Weekly Contest 23
LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...
- 【Leetcode_easy】933. Number of Recent Calls
problem 933. Number of Recent Calls 参考 1. Leetcode_easy_933. Number of Recent Calls; 完
- Leetcode Weekly Contest 86
Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...
- LeetCode Weekly Contest
链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...
随机推荐
- java 解析xml(dom4j.jar)
先导入jar包 <?xml version="1.0" encoding="UTF-8"?> <companys> <compan ...
- virsh 查看hypervisor特性
[root@opennebula var]# virsh -c qemu:///system nodeinfo CPU model: x86_64 CPU(s): CPU frequency: MHz ...
- golang hello
package main import "fmt" func main() { fmt.Printf("Hello, world.\n") }
- 新装的Ubuntu没有ipconfig和ping命令
新装的Ubuntu或者Docker pull的Ubuntu镜像创建的容器没有ipconfig和ping命令 解决办法: 1.apt-get update 2.安装和ifconfig有关的工具 apt ...
- poj1722 SUBTRACT
应该是基础的dp练手题 线性dp最主要的就是关于阶段的划分,这个题中我没想到的一点就是开状态的时候使用了前i个数能合成的数来记录 我自己的想法就是类似于区间dp这样的记录方法,这种方法确实开了很多冗余 ...
- Open Message Queue 集群问题
nohup ./imqbrokerd -tty -name myBroker -port 7677 -javahome /opt/omae/jdk1.7.0_45 -cluster 192.168.2 ...
- Detailed ASP.NET MVC Pipeline
Posted By : Shailendra Chauhan, 27 Jan 2014 P.NET MVC is an open source framework built on the top o ...
- 跨域Ajax请求(jQuery JSONP MVC)
通过jQuery的$.ajax方法发送JSONP请求 js代码 <script type="text/javascript"> function jsonptest2( ...
- springMVC工作原理趣味解析
springMVC 涉及的人有: 1:浏览器 2:DispatherServlet 3:Handler 4:HandlerAdapter ...
- 【C#】LINQ
一.什么是LINQ 长期以来,开发社区形成以下的格局: 1.面向对象与数据访问两个领域长期分裂,各自为政. 2.编程语言中的数据类型与数据库中的数据类型形成两套不同的体系,例如: C#中字符串用str ...