1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/originData/find-winner-on-a-tic-tac-toe-game.json

193 lines
18 KiB
JSON
Raw Normal View History

2022-03-27 18:27:43 +08:00
{
"data": {
"question": {
"questionId": "1400",
"questionFrontendId": "1275",
"boundTopicId": null,
"title": "Find Winner on a Tic Tac Toe Game",
"titleSlug": "find-winner-on-a-tic-tac-toe-game",
2023-12-09 18:42:21 +08:00
"content": "<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p>\n\n<ul>\n\t<li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li>\n\t<li>The first player <code>A</code> always places <code>&#39;X&#39;</code> characters, while the second player <code>B</code> always places <code>&#39;O&#39;</code> characters.</li>\n\t<li><code>&#39;X&#39;</code> and <code>&#39;O&#39;</code> characters are always placed into empty squares, never on filled ones.</li>\n\t<li>The game ends when there are <strong>three</strong> of the same (non-empty) character filling any row, column, or diagonal.</li>\n\t<li>The game also ends if all squares are non-empty.</li>\n\t<li>No more moves can be played if the game is over.</li>\n</ul>\n\n<p>Given a 2D integer array <code>moves</code> where <code>moves[i] = [row<sub>i</sub>, col<sub>i</sub>]</code> indicates that the <code>i<sup>th</sup></code> move will be played on <code>grid[row<sub>i</sub>][col<sub>i</sub>]</code>. return <em>the winner of the game if it exists</em> (<code>A</code> or <code>B</code>). In case the game ends in a draw return <code>&quot;Draw&quot;</code>. If there are still movements to play return <code>&quot;Pending&quot;</code>.</p>\n\n<p>You can assume that <code>moves</code> is valid (i.e., it follows the rules of <strong>Tic-Tac-Toe</strong>), the grid is initially empty, and <code>A</code> will play first.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/22/xo1-grid.jpg\" style=\"width: 244px; height: 245px;\" />\n<pre>\n<strong>Input:</strong> moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]\n<strong>Output:</strong> &quot;A&quot;\n<strong>Explanation:</strong> A wins, they always play first.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/22/xo2-grid.jpg\" style=\"width: 244px; height: 245px;\" />\n<pre>\n<strong>Input:</strong> moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\n<strong>Output:</strong> &quot;B&quot;\n<strong>Explanation:</strong> B wins.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/22/xo3-grid.jpg\" style=\"width: 244px; height: 245px;\" />\n<pre>\n<strong>Input:</strong> moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]\n<strong>Output:</strong> &quot;Draw&quot;\n<strong>Explanation:</strong> The game ends in a draw since there are no moves to make.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= moves.length &lt;= 9</code></li>\n\t<li><code>moves[i].length == 2</code></li>\n\t<li><code>0 &lt;= row<sub>i</sub>, col<sub>i</sub> &lt;= 2</code></li>\n\t<li>There are no repeated elements on <code>moves</code>.</li>\n\t<li><code>moves</code> follow the rules of tic tac toe.</li>\n</ul>\n",
2022-03-27 18:27:43 +08:00
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Easy",
2023-12-09 18:42:21 +08:00
"likes": 1410,
"dislikes": 326,
2022-03-27 18:27:43 +08:00
"isLiked": null,
2023-12-09 18:42:21 +08:00
"similarQuestions": "[{\"title\": \"Categorize Box According to Criteria\", \"titleSlug\": \"categorize-box-according-to-criteria\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
2022-03-27 18:27:43 +08:00
"exampleTestcases": "[[0,0],[2,0],[1,1],[2,1],[2,2]]\n[[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\n[[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Hash Table",
"slug": "hash-table",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Matrix",
"slug": "matrix",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Simulation",
"slug": "simulation",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n \n }\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "class Solution {\n public String tictactoe(int[][] moves) {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class Solution(object):\n def tictactoe(self, moves):\n \"\"\"\n :type moves: List[List[int]]\n :rtype: str\n \"\"\"\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "class Solution:\n def tictactoe(self, moves: List[List[int]]) -> str:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
2023-12-09 18:42:21 +08:00
"code": "char* tictactoe(int** moves, int movesSize, int* movesColSize) {\n \n}",
2022-03-27 18:27:43 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "public class Solution {\n public string Tictactoe(int[][] moves) {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\n * @param {number[][]} moves\n * @return {string}\n */\nvar tictactoe = function(moves) {\n \n};",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "TypeScript",
"langSlug": "typescript",
"code": "function tictactoe(moves: number[][]): string {\n \n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "PHP",
"langSlug": "php",
"code": "class Solution {\n\n /**\n * @param Integer[][] $moves\n * @return String\n */\n function tictactoe($moves) {\n \n }\n}",
2022-03-27 18:27:43 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Swift",
"langSlug": "swift",
"code": "class Solution {\n func tictactoe(_ moves: [[Int]]) -> String {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
2023-12-09 18:42:21 +08:00
{
"lang": "Kotlin",
"langSlug": "kotlin",
"code": "class Solution {\n fun tictactoe(moves: Array<IntArray>): String {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Dart",
"langSlug": "dart",
"code": "class Solution {\n String tictactoe(List<List<int>> moves) {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
2022-03-27 18:27:43 +08:00
{
"lang": "Go",
"langSlug": "golang",
"code": "func tictactoe(moves [][]int) string {\n \n}",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Ruby",
"langSlug": "ruby",
"code": "# @param {Integer[][]} moves\n# @return {String}\ndef tictactoe(moves)\n \nend",
2022-03-27 18:27:43 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Scala",
"langSlug": "scala",
"code": "object Solution {\n def tictactoe(moves: Array[Array[Int]]): String = {\n \n }\n}",
2022-03-27 18:27:43 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Rust",
"langSlug": "rust",
"code": "impl Solution {\n pub fn tictactoe(moves: Vec<Vec<i32>>) -> String {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Racket",
"langSlug": "racket",
"code": "(define/contract (tictactoe moves)\n (-> (listof (listof exact-integer?)) string?)\n )",
2022-03-27 18:27:43 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Erlang",
"langSlug": "erlang",
"code": "-spec tictactoe(Moves :: [[integer()]]) -> unicode:unicode_binary().\ntictactoe(Moves) ->\n .",
"__typename": "CodeSnippetNode"
},
{
"lang": "Elixir",
"langSlug": "elixir",
2023-12-09 18:42:21 +08:00
"code": "defmodule Solution do\n @spec tictactoe(moves :: [[integer]]) :: String.t\n def tictactoe(moves) do\n \n end\nend",
2022-03-27 18:27:43 +08:00
"__typename": "CodeSnippetNode"
}
],
2023-12-09 18:42:21 +08:00
"stats": "{\"totalAccepted\": \"115.4K\", \"totalSubmission\": \"213.4K\", \"totalAcceptedRaw\": 115399, \"totalSubmissionRaw\": 213398, \"acRate\": \"54.1%\"}",
2022-03-27 18:27:43 +08:00
"hints": [
"It's straightforward to check if A or B won or not, check for each row/column/diag if all the three are the same.",
"Then if no one wins, the game is a draw iff the board is full, i.e. moves.length = 9 otherwise is pending."
],
"solution": {
"id": "1168",
"canSeeDetail": false,
"paidOnly": true,
"hasVideoSolution": false,
"paidOnlyVideo": true,
"__typename": "ArticleNode"
},
"status": null,
"sampleTestCase": "[[0,0],[2,0],[1,1],[2,1],[2,2]]",
"metaData": "{\n \"name\": \"tictactoe\",\n \"params\": [\n {\n \"name\": \"moves\",\n \"type\": \"integer[][]\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n }\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": true,
2023-12-09 18:42:21 +08:00
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 20 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code>OpenJDK 17</code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu11 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\"], \"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://githu
2022-03-27 18:27:43 +08:00
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}