classDataStream:def__init__(self,value:int,k:int):self.val,self.k=value,kself.cnt=0defconsec(self,num:int)->bool:self.cnt=0ifnum!=self.valelseself.cnt+1returnself.cnt>=self.k# Your DataStream object will be instantiated and called as such:# obj = DataStream(value, k)# param_1 = obj.consec(num)
1 2 3 4 5 6 7 8 9101112131415161718192021
classDataStream{privateintcnt;privateintval;privateintk;publicDataStream(intvalue,intk){val=value;this.k=k;}publicbooleanconsec(intnum){cnt=num==val?cnt+1:0;returncnt>=k;}}/** * Your DataStream object will be instantiated and called as such: * DataStream obj = new DataStream(value, k); * boolean param_1 = obj.consec(num); */
1 2 3 4 5 6 7 8 910111213141516171819202122
classDataStream{public:DataStream(intvalue,intk){val=value;this->k=k;}boolconsec(intnum){cnt=num==val?cnt+1:0;returncnt>=k;}private:intcnt=0;intval,k;};/** * Your DataStream object will be instantiated and called as such: * DataStream* obj = new DataStream(value, k); * bool param_1 = obj->consec(num); */
1 2 3 4 5 6 7 8 910111213141516171819202122
typeDataStreamstruct{val,k,cntint}funcConstructor(valueint,kint)DataStream{returnDataStream{value,k,0}}func(this*DataStream)Consec(numint)bool{ifnum==this.val{this.cnt++}else{this.cnt=0}returnthis.cnt>=this.k}/** * Your DataStream object will be instantiated and called as such: * obj := Constructor(value, k); * param_1 := obj.Consec(num); */
1 2 3 4 5 6 7 8 910111213141516171819202122
classDataStream{privateval:number;privatek:number;privatecnt:number;constructor(value:number,k:number){this.val=value;this.k=k;this.cnt=0;}consec(num:number):boolean{this.cnt=this.val===num?this.cnt+1:0;returnthis.cnt>=this.k;}}/** * Your DataStream object will be instantiated and called as such: * var obj = new DataStream(value, k) * var param_1 = obj.consec(num) */