classTicTacToe:def__init__(self,n:int):self.n=nself.cnt=[defaultdict(int),defaultdict(int)]defmove(self,row:int,col:int,player:int)->int:cur=self.cnt[player-1]n=self.ncur[row]+=1cur[n+col]+=1ifrow==col:cur[n<<1]+=1ifrow+col==n-1:cur[n<<1|1]+=1ifany(cur[i]==nforiin(row,n+col,n<<1,n<<1|1)):returnplayerreturn0# Your TicTacToe object will be instantiated and called as such:# obj = TicTacToe(n)# param_1 = obj.move(row,col,player)
classTicTacToe{privateintn;privateint[][]cnt;publicTicTacToe(intn){this.n=n;cnt=newint[2][(n<<1)+2];}publicintmove(introw,intcol,intplayer){int[]cur=cnt[player-1];++cur[row];++cur[n+col];if(row==col){++cur[n<<1];}if(row+col==n-1){++cur[n<<1|1];}if(cur[row]==n||cur[n+col]==n||cur[n<<1]==n||cur[n<<1|1]==n){returnplayer;}return0;}}/** * Your TicTacToe object will be instantiated and called as such: * TicTacToe obj = new TicTacToe(n); * int param_1 = obj.move(row,col,player); */
classTicTacToe{private:intn;vector<vector<int>>cnt;public:TicTacToe(intn):n(n),cnt(2,vector<int>((n<<1)+2,0)){}intmove(introw,intcol,intplayer){vector<int>&cur=cnt[player-1];++cur[row];++cur[n+col];if(row==col){++cur[n<<1];}if(row+col==n-1){++cur[n<<1|1];}if(cur[row]==n||cur[n+col]==n||cur[n<<1]==n||cur[n<<1|1]==n){returnplayer;}return0;}};/** * Your TicTacToe object will be instantiated and called as such: * TicTacToe* obj = new TicTacToe(n); * int param_1 = obj->move(row,col,player); */
typeTicTacToestruct{nintcnt[][]int}funcConstructor(nint)TicTacToe{cnt:=make([][]int,2)fori:=rangecnt{cnt[i]=make([]int,(n<<1)+2)}returnTicTacToe{n,cnt}}func(this*TicTacToe)Move(rowint,colint,playerint)int{cur:=this.cnt[player-1]cur[row]++cur[this.n+col]++ifrow==col{cur[this.n<<1]++}ifrow+col==this.n-1{cur[this.n<<1|1]++}ifcur[row]==this.n||cur[this.n+col]==this.n||cur[this.n<<1]==this.n||cur[this.n<<1|1]==this.n{returnplayer}return0}/** * Your TicTacToe object will be instantiated and called as such: * obj := Constructor(n); * param_1 := obj.Move(row,col,player); */
classTicTacToe{privaten:number;privatecnt:number[][];constructor(n:number){this.n=n;this.cnt=[Array((n<<1)+2).fill(0),Array((n<<1)+2).fill(0)];}move(row:number,col:number,player:number):number{constcur=this.cnt[player-1];cur[row]++;cur[this.n+col]++;if(row===col){cur[this.n<<1]++;}if(row+col===this.n-1){cur[(this.n<<1)|1]++;}if(cur[row]===this.n||cur[this.n+col]===this.n||cur[this.n<<1]===this.n||cur[(this.n<<1)|1]===this.n){returnplayer;}return0;}}/** * Your TicTacToe object will be instantiated and called as such: * var obj = new TicTacToe(n) * var param_1 = obj.move(row,col,player) */