classTextEditor:def__init__(self):self.left=[]self.right=[]defaddText(self,text:str)->None:self.left.extend(list(text))defdeleteText(self,k:int)->int:k=min(k,len(self.left))for_inrange(k):self.left.pop()returnkdefcursorLeft(self,k:int)->str:k=min(k,len(self.left))for_inrange(k):self.right.append(self.left.pop())return''.join(self.left[-10:])defcursorRight(self,k:int)->str:k=min(k,len(self.right))for_inrange(k):self.left.append(self.right.pop())return''.join(self.left[-10:])# Your TextEditor object will be instantiated and called as such:# obj = TextEditor()# obj.addText(text)# param_2 = obj.deleteText(k)# param_3 = obj.cursorLeft(k)# param_4 = obj.cursorRight(k)
classTextEditor{privateStringBuilderleft=newStringBuilder();privateStringBuilderright=newStringBuilder();publicTextEditor(){}publicvoidaddText(Stringtext){left.append(text);}publicintdeleteText(intk){k=Math.min(k,left.length());left.setLength(left.length()-k);returnk;}publicStringcursorLeft(intk){k=Math.min(k,left.length());for(inti=0;i<k;++i){right.append(left.charAt(left.length()-1));left.deleteCharAt(left.length()-1);}returnleft.substring(Math.max(left.length()-10,0));}publicStringcursorRight(intk){k=Math.min(k,right.length());for(inti=0;i<k;++i){left.append(right.charAt(right.length()-1));right.deleteCharAt(right.length()-1);}returnleft.substring(Math.max(left.length()-10,0));}}/** * Your TextEditor object will be instantiated and called as such: * TextEditor obj = new TextEditor(); * obj.addText(text); * int param_2 = obj.deleteText(k); * String param_3 = obj.cursorLeft(k); * String param_4 = obj.cursorRight(k); */
classTextEditor{public:TextEditor(){}voidaddText(stringtext){left+=text;}intdeleteText(intk){k=min(k,(int)left.size());left.resize(left.size()-k);returnk;}stringcursorLeft(intk){k=min(k,(int)left.size());while(k--){right+=left.back();left.pop_back();}returnleft.substr(max(0,(int)left.size()-10));}stringcursorRight(intk){k=min(k,(int)right.size());while(k--){left+=right.back();right.pop_back();}returnleft.substr(max(0,(int)left.size()-10));}private:stringleft,right;};/** * Your TextEditor object will be instantiated and called as such: * TextEditor* obj = new TextEditor(); * obj->addText(text); * int param_2 = obj->deleteText(k); * string param_3 = obj->cursorLeft(k); * string param_4 = obj->cursorRight(k); */
classTextEditor{privateleft:string[];privateright:string[];constructor(){this.left=[];this.right=[];}addText(text:string):void{this.left.push(...text);}deleteText(k:number):number{k=Math.min(k,this.left.length);for(leti=0;i<k;i++){this.left.pop();}returnk;}cursorLeft(k:number):string{k=Math.min(k,this.left.length);for(leti=0;i<k;i++){this.right.push(this.left.pop()!);}returnthis.left.slice(-10).join('');}cursorRight(k:number):string{k=Math.min(k,this.right.length);for(leti=0;i<k;i++){this.left.push(this.right.pop()!);}returnthis.left.slice(-10).join('');}}/** * Your TextEditor object will be instantiated and called as such: * var obj = new TextEditor() * obj.addText(text) * var param_2 = obj.deleteText(k) * var param_3 = obj.cursorLeft(k) * var param_4 = obj.cursorRight(k) */