尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
LeetCode //C - 1275. Find Winner on a Tic Tac Toe Game
1275. Find Winner on a Tic Tac Toe GameTic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are:Players take turns placing characters into empty squares ’ .The first player A always places ‘X’ characters, while the second player B always places ‘O’ characters.‘X’ and ‘O’ characters are always placed into empty squares, never on filled ones.The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.The game also ends if all squares are non-empty.No more moves can be played if the game is over.Given a 2D integer array moves wherem o v e s [ i ] [ r o w i , c o l i ] moves[i] [row_i, col_i]moves[i][rowi​,coli​]indicates that thei t h i^{th}ithmove will be played ong r i d [ r o w i ] [ c o l i ] grid[row_i][col_i]grid[rowi​][coli​]. return the winner of the game if it exists (A or B). In case the game ends in a draw return “Draw”. If there are still movements to play return “Pending”.You can assume that moves is valid (i.e., it follows the rules of Tic-Tac-Toe), the grid is initially empty, and A will play first.Example 1:Input:moves [[0,0],[2,0],[1,1],[2,1],[2,2]]Output:“A”Explanation:A wins, they always play first.Example 2:Input:moves [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]Output:“B”Explanation:TB wins.Example 3:Input:moves [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]Output:“Draw”Explanation:The game ends in a draw since there are no moves to make.Constraints:1 moves.length 9moves[i].length 20 r o w i , c o l i 2 0 row_i, col_i 20rowi​,coli​2There are no repeated elements on moves.moves follow the rules of tic tac toe.From: LeetCodeLink: 1275. Find Winner on a Tic Tac Toe GameSolution:Ideas:put A as 1, B as -1.If any row, column, or diagonal sums to 3, A wins.If it sums to -3, B wins.Code:char*tictactoe(int**moves,intmovesSize,int*movesColSize){intboard[3][3]{0};// A 1, B -1for(inti0;imovesSize;i){intrmoves[i][0];intcmoves[i][1];board[r][c](i%20)?1:-1;}for(inti0;i3;i){introwboard[i][0]board[i][1]board[i][2];intcolboard[0][i]board[1][i]board[2][i];if(row3||col3)returnA;if(row-3||col-3)returnB;}intdiag1board[0][0]board[1][1]board[2][2];intdiag2board[0][2]board[1][1]board[2][0];if(diag13||diag23)returnA;if(diag1-3||diag2-3)returnB;if(movesSize9)returnDraw;returnPending;}
RELATED

相关推荐

@gitbook/react-math:KaTeX 优先、MathJax 兜底的 React 数学公式渲染组件

@gitbook/react-math:KaTeX 优先、MathJax 兜底的 React 数学公式渲染组件

前端后端知识管理 【免费下载链接】gitbook The open source frontend for GitBook doc sites 项目地址: https://gitcode.com/gh_mirrors/gi/gitbook 点击查看 免费下载 导读 gitbook/react-math 是 GitBook 开源前端(gitbook 仓库)中负责…

📅 2026/10/1 2:32:33
Asp.net MVC4企业级源码实战:CMS+CRM+OA+MSSQL跑通与避坑指南

Asp.net MVC4企业级源码实战:CMS+CRM+OA+MSSQL跑通与避坑指南

简介:这是一套面向.NET开发者的企业级项目完整源码,基于Asp.net MVC4构建,整合CMS内容管理、CRM客户关系与OA办公三大业务系统,适合有一定MVC基础、希望深入理解分层架构与通用组件设计的开发者参考学习。压缩包共1719个文件&…

📅 2026/10/1 2:32:33
ESP32-CAM图像传输全攻略:硬件接线、源码解析与Python接收端

ESP32-CAM图像传输全攻略:硬件接线、源码解析与Python接收端

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/10/1 2:27:33
MORE NEWS

更多资讯

📰

王者万象棋庄小鱼好用吗 王者万象棋庄小鱼怎么样

王者万象棋庄小鱼是一位特殊的棋手角色。很多玩家想知道王者万象棋庄小鱼好用吗,作为以策略调度为核心的棋手,自身不提供直接输出,所有强度都依赖卡牌协同与体系构建。王者万象棋庄小鱼好用吗?这篇文章就让我们一起看看&#xff0…

📰

大模型入门到实战:参数、Token、RAG与本地部署全解析

“大模型”这个词最近刷屏的频率有多高,不用我再强调了。无论是AI从业者、程序员、产品经理,还是单纯刷短视频的普通用户,几乎每天都能看到“大模型”三个字。但说实话,很多人对“大模型”的理解,其实停留在“一个很厉…

📰

Veeam备份原理与组件拆解:数据流、CBT与一致性

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📰

GPT-5.5以93.16分居首:2026-09-28 Smoke快测数据简报

2026-09-28 赢政指数 Smoke 快测覆盖 11 个模型,GPT-5.5 以 93.16 分位居当日首位。Smoke 为每日 10 题快测,适合观察短期信号,不等同 Full 周榜结论。 本次 Smoke 评测只覆盖代码执行和材料约束两个主榜维度,主榜公式为 0.55 代…

📰

全国有哪些值得推荐的机械设备APP开发公司?

摘要:全国值得推荐的机械设备APP开发公司,要懂设备全生命周期:台账、点检、维保、故障工单、远程运维和OEE效率分析,而不是做个设备信息展示页。机械设备App常要对接物联网采集数据,支持现场报修和远程监控。选型看设备…

📰

基于OpenCV的色块追踪颜色识别源码技术解析与调优实战指南

简介:一套基于OpenCV实现的色块追踪与颜色识别完整项目,面向计算机、电子信息等专业的课程设计、期末大作业及毕设场景,也适合希望快速上手视觉识别的初学者。压缩包共35个文件,约6.43MB,其中包含5个Python脚本、6个Ma…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬