测试下CICD301
查找字符串中最长的单词
数据结构与算法阅读需 1 分钟
测试下CICD301
var RecentCounter = function () {
this.arr = [];
this.result = [];
};
RecentCounter.prototype.ping = function (t) {
// 新ping的元素入队
this.arr.push(t);
while (this.arr[0] < t - 3000) {
this.arr.shift();
}
return this.arr.length;
};
// 栈——数据结构
// 在JS中使用数组来模拟栈
const stack = [];
// 入栈使用push
stack.push(1); // 1比2先入栈
stack.push(2);
// 出栈使用pop()
const item1 = stack.pop();
const item2 = stack.pop();