<分区> 分区>
Given constant integers x and t, write a function that takes no argument and returns true if the function has been called x number of times in last t secs.
这是我对一个可能算法的伪代码/C++ 实现,但我不确定它是否正确/有效:
const int x;
const int t;
vector<long> v;
boolean countNumberOfTimesBeenCalled(){
int numberOfCallsInLastTSeconds=0;
v.push_back(System.currentTimeInMillis());
for(int x=0; x<v.size();x++){
if((v.at(x)>=(System.currentTimeInMillis()-1000*t))&&(v.at(x)<=System.currentTimeInMillis())
numberOfCallsInLastTSeconds++;
}
if(numberOfCallsInLastTSeconds==x)
return true;
else
return false;
}
谁能提出替代方案?