1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 00:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/originData/design-spreadsheet.json
2025-04-03 23:09:51 +08:00

203 lines
39 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"data": {
"question": {
"questionId": "3797",
"questionFrontendId": "3484",
"categoryTitle": "Algorithms",
"boundTopicId": 3612464,
"title": "Design Spreadsheet",
"titleSlug": "design-spreadsheet",
"content": "<p>A spreadsheet is a grid with 26 columns (labeled from <code>&#39;A&#39;</code> to <code>&#39;Z&#39;</code>) and a given number of <code>rows</code>. Each cell in the spreadsheet can hold an integer value between 0 and 10<sup>5</sup>.</p>\n\n<p>Implement the <code>Spreadsheet</code> class:</p>\n\n<ul>\n\t<li><code>Spreadsheet(int rows)</code> Initializes a spreadsheet with 26 columns (labeled <code>&#39;A&#39;</code> to <code>&#39;Z&#39;</code>) and the specified number of rows. All cells are initially set to 0.</li>\n\t<li><code>void setCell(String cell, int value)</code> Sets the value of the specified <code>cell</code>. The cell reference is provided in the format <code>&quot;AX&quot;</code> (e.g., <code>&quot;A1&quot;</code>, <code>&quot;B10&quot;</code>), where the letter represents the column (from <code>&#39;A&#39;</code> to <code>&#39;Z&#39;</code>) and the number represents a <strong>1-indexed</strong> row.</li>\n\t<li><code>void resetCell(String cell)</code> Resets the specified cell to 0.</li>\n\t<li><code>int getValue(String formula)</code> Evaluates a formula of the form <code>&quot;=X+Y&quot;</code>, where <code>X</code> and <code>Y</code> are <strong>either</strong> cell references or non-negative integers, and returns the computed sum.</li>\n</ul>\n\n<p><strong>Note:</strong> If <code>getValue</code> references a cell that has not been explicitly set using <code>setCell</code>, its value is considered 0.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong><br />\n<span class=\"example-io\">[&quot;Spreadsheet&quot;, &quot;getValue&quot;, &quot;setCell&quot;, &quot;getValue&quot;, &quot;setCell&quot;, &quot;getValue&quot;, &quot;resetCell&quot;, &quot;getValue&quot;]<br />\n[[3], [&quot;=5+7&quot;], [&quot;A1&quot;, 10], [&quot;=A1+6&quot;], [&quot;B2&quot;, 15], [&quot;=A1+B2&quot;], [&quot;A1&quot;], [&quot;=A1+B2&quot;]]</span></p>\n\n<p><strong>Output:</strong><br />\n<span class=\"example-io\">[null, 12, null, 16, null, 25, null, 15] </span></p>\n\n<p><strong>Explanation</strong></p>\nSpreadsheet spreadsheet = new Spreadsheet(3); // Initializes a spreadsheet with 3 rows and 26 columns<br data-end=\"321\" data-start=\"318\" />\nspreadsheet.getValue(&quot;=5+7&quot;); // returns 12 (5+7)<br data-end=\"373\" data-start=\"370\" />\nspreadsheet.setCell(&quot;A1&quot;, 10); // sets A1 to 10<br data-end=\"423\" data-start=\"420\" />\nspreadsheet.getValue(&quot;=A1+6&quot;); // returns 16 (10+6)<br data-end=\"477\" data-start=\"474\" />\nspreadsheet.setCell(&quot;B2&quot;, 15); // sets B2 to 15<br data-end=\"527\" data-start=\"524\" />\nspreadsheet.getValue(&quot;=A1+B2&quot;); // returns 25 (10+15)<br data-end=\"583\" data-start=\"580\" />\nspreadsheet.resetCell(&quot;A1&quot;); // resets A1 to 0<br data-end=\"634\" data-start=\"631\" />\nspreadsheet.getValue(&quot;=A1+B2&quot;); // returns 15 (0+15)</div>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= rows &lt;= 10<sup>3</sup></code></li>\n\t<li><code>0 &lt;= value &lt;= 10<sup>5</sup></code></li>\n\t<li>The formula is always in the format <code>&quot;=X+Y&quot;</code>, where <code>X</code> and <code>Y</code> are either valid cell references or <strong>non-negative</strong> integers with values less than or equal to <code>10<sup>5</sup></code>.</li>\n\t<li>Each cell reference consists of a capital letter from <code>&#39;A&#39;</code> to <code>&#39;Z&#39;</code> followed by a row number between <code>1</code> and <code>rows</code>.</li>\n\t<li>At most <code>10<sup>4</sup></code> calls will be made in <strong>total</strong> to <code>setCell</code>, <code>resetCell</code>, and <code>getValue</code>.</li>\n</ul>\n",
"translatedTitle": "设计电子表格",
"translatedContent": "<p>电子表格是一个网格,它有 26 列(从 <code>'A'</code> 到 <code>'Z'</code>)和指定数量的 <code>rows</code>。每个单元格可以存储一个 0 到 10<sup>5</sup>&nbsp;之间的整数值。</p>\n\n<p>请你实现一个&nbsp;<code>Spreadsheet</code> 类:</p>\n\n<ul>\n\t<li><code>Spreadsheet(int rows)</code> 初始化一个具有 26 列(从 <code>'A'</code> 到 <code>'Z'</code>)和指定行数的电子表格。所有单元格最初的值都为 0 。</li>\n\t<li><code>void setCell(String cell, int value)</code> 设置指定单元格的值。单元格引用以 <code>\"AX\"</code> 的格式提供(例如,<code>\"A1\"</code><code>\"B10\"</code>),其中字母表示列(从 <code>'A'</code> 到 <code>'Z'</code>),数字表示从<strong>&nbsp;</strong><strong>1</strong>&nbsp;开始的行号。</li>\n\t<li><code>void resetCell(String cell)</code> 重置指定单元格的值为 0 。</li>\n\t<li><code>int getValue(String formula)</code> 计算一个公式的值,格式为 <code>\"=X+Y\"</code>,其中 <code>X</code> 和 <code>Y</code>&nbsp;<strong>要么</strong> 是单元格引用,要么非负整数,返回计算的和。</li>\n</ul>\n\n<p><strong>注意:</strong> 如果 <code>getValue</code> 引用一个未通过 <code>setCell</code> 明确设置的单元格,则该单元格的值默认为 0 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<div class=\"example-block\">\n<p><strong>输入:</strong><br />\n<span class=\"example-io\">[\"Spreadsheet\", \"getValue\", \"setCell\", \"getValue\", \"setCell\", \"getValue\", \"resetCell\", \"getValue\"]<br />\n[[3], [\"=5+7\"], [\"A1\", 10], [\"=A1+6\"], [\"B2\", 15], [\"=A1+B2\"], [\"A1\"], [\"=A1+B2\"]]</span></p>\n\n<p><strong>输出:</strong><br />\n<span class=\"example-io\">[null, 12, null, 16, null, 25, null, 15] </span></p>\n\n<p><strong>解释</strong></p>\nSpreadsheet spreadsheet = new Spreadsheet(3); // 初始化一个具有 3 行和 26 列的电子表格<br data-end=\"321\" data-start=\"318\" />\nspreadsheet.getValue(\"=5+7\"); // 返回 12 (5+7)<br data-end=\"373\" data-start=\"370\" />\nspreadsheet.setCell(\"A1\", 10); // 设置 A1 为 10<br data-end=\"423\" data-start=\"420\" />\nspreadsheet.getValue(\"=A1+6\"); // 返回 16 (10+6)<br data-end=\"477\" data-start=\"474\" />\nspreadsheet.setCell(\"B2\", 15); // 设置 B2 为 15<br data-end=\"527\" data-start=\"524\" />\nspreadsheet.getValue(\"=A1+B2\"); // 返回 25 (10+15)<br data-end=\"583\" data-start=\"580\" />\nspreadsheet.resetCell(\"A1\"); // 重置 A1 为 0<br data-end=\"634\" data-start=\"631\" />\nspreadsheet.getValue(\"=A1+B2\"); // 返回 15 (0+15)</div>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= rows &lt;= 10<sup>3</sup></code></li>\n\t<li><code>0 &lt;= value &lt;= 10<sup>5</sup></code></li>\n\t<li>公式保证采用 <code>\"=X+Y\"</code> 格式,其中 <code>X</code> 和 <code>Y</code> 要么是有效的单元格引用,要么是小于等于 <code>10<sup>5</sup></code> 的 <strong>非负</strong> 整数。</li>\n\t<li>每个单元格引用由一个大写字母 <code>'A'</code> 到 <code>'Z'</code> 和一个介于 <code>1</code> 和 <code>rows</code> 之间的行号组成。</li>\n\t<li><strong>总共</strong> 最多会对 <code>setCell</code>、<code>resetCell</code> 和 <code>getValue</code> 调用 <code>10<sup>4</sup></code> 次。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 2,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Excel Sheet Column Title\", \"titleSlug\": \"excel-sheet-column-title\", \"difficulty\": \"Easy\", \"translatedTitle\": \"Excel \\u8868\\u5217\\u540d\\u79f0\", \"isPaidOnly\": false}]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false, \"cangjie\": false}",
"topicTags": [
{
"name": "Design",
"slug": "design",
"translatedName": "设计",
"__typename": "TopicTagNode"
},
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Hash Table",
"slug": "hash-table",
"translatedName": "哈希表",
"__typename": "TopicTagNode"
},
{
"name": "String",
"slug": "string",
"translatedName": "字符串",
"__typename": "TopicTagNode"
},
{
"name": "Matrix",
"slug": "matrix",
"translatedName": "矩阵",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "class Spreadsheet {\npublic:\n Spreadsheet(int rows) {\n \n }\n \n void setCell(string cell, int value) {\n \n }\n \n void resetCell(string cell) {\n \n }\n \n int getValue(string formula) {\n \n }\n};\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * Spreadsheet* obj = new Spreadsheet(rows);\n * obj->setCell(cell,value);\n * obj->resetCell(cell);\n * int param_3 = obj->getValue(formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "class Spreadsheet {\n\n public Spreadsheet(int rows) {\n \n }\n \n public void setCell(String cell, int value) {\n \n }\n \n public void resetCell(String cell) {\n \n }\n \n public int getValue(String formula) {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * Spreadsheet obj = new Spreadsheet(rows);\n * obj.setCell(cell,value);\n * obj.resetCell(cell);\n * int param_3 = obj.getValue(formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class Spreadsheet(object):\n\n def __init__(self, rows):\n \"\"\"\n :type rows: int\n \"\"\"\n \n\n def setCell(self, cell, value):\n \"\"\"\n :type cell: str\n :type value: int\n :rtype: None\n \"\"\"\n \n\n def resetCell(self, cell):\n \"\"\"\n :type cell: str\n :rtype: None\n \"\"\"\n \n\n def getValue(self, formula):\n \"\"\"\n :type formula: str\n :rtype: int\n \"\"\"\n \n\n\n# Your Spreadsheet object will be instantiated and called as such:\n# obj = Spreadsheet(rows)\n# obj.setCell(cell,value)\n# obj.resetCell(cell)\n# param_3 = obj.getValue(formula)",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "class Spreadsheet:\n\n def __init__(self, rows: int):\n \n\n def setCell(self, cell: str, value: int) -> None:\n \n\n def resetCell(self, cell: str) -> None:\n \n\n def getValue(self, formula: str) -> int:\n \n\n\n# Your Spreadsheet object will be instantiated and called as such:\n# obj = Spreadsheet(rows)\n# obj.setCell(cell,value)\n# obj.resetCell(cell)\n# param_3 = obj.getValue(formula)",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
"code": "\n\n\ntypedef struct {\n \n} Spreadsheet;\n\n\nSpreadsheet* spreadsheetCreate(int rows) {\n \n}\n\nvoid spreadsheetSetCell(Spreadsheet* obj, char* cell, int value) {\n \n}\n\nvoid spreadsheetResetCell(Spreadsheet* obj, char* cell) {\n \n}\n\nint spreadsheetGetValue(Spreadsheet* obj, char* formula) {\n \n}\n\nvoid spreadsheetFree(Spreadsheet* obj) {\n \n}\n\n/**\n * Your Spreadsheet struct will be instantiated and called as such:\n * Spreadsheet* obj = spreadsheetCreate(rows);\n * spreadsheetSetCell(obj, cell, value);\n \n * spreadsheetResetCell(obj, cell);\n \n * int param_3 = spreadsheetGetValue(obj, formula);\n \n * spreadsheetFree(obj);\n*/",
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "public class Spreadsheet {\n\n public Spreadsheet(int rows) {\n \n }\n \n public void SetCell(string cell, int value) {\n \n }\n \n public void ResetCell(string cell) {\n \n }\n \n public int GetValue(string formula) {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * Spreadsheet obj = new Spreadsheet(rows);\n * obj.SetCell(cell,value);\n * obj.ResetCell(cell);\n * int param_3 = obj.GetValue(formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\n * @param {number} rows\n */\nvar Spreadsheet = function(rows) {\n \n};\n\n/** \n * @param {string} cell \n * @param {number} value\n * @return {void}\n */\nSpreadsheet.prototype.setCell = function(cell, value) {\n \n};\n\n/** \n * @param {string} cell\n * @return {void}\n */\nSpreadsheet.prototype.resetCell = function(cell) {\n \n};\n\n/** \n * @param {string} formula\n * @return {number}\n */\nSpreadsheet.prototype.getValue = function(formula) {\n \n};\n\n/** \n * Your Spreadsheet object will be instantiated and called as such:\n * var obj = new Spreadsheet(rows)\n * obj.setCell(cell,value)\n * obj.resetCell(cell)\n * var param_3 = obj.getValue(formula)\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "TypeScript",
"langSlug": "typescript",
"code": "class Spreadsheet {\n constructor(rows: number) {\n \n }\n\n setCell(cell: string, value: number): void {\n \n }\n\n resetCell(cell: string): void {\n \n }\n\n getValue(formula: string): number {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * var obj = new Spreadsheet(rows)\n * obj.setCell(cell,value)\n * obj.resetCell(cell)\n * var param_3 = obj.getValue(formula)\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "PHP",
"langSlug": "php",
"code": "class Spreadsheet {\n /**\n * @param Integer $rows\n */\n function __construct($rows) {\n \n }\n \n /**\n * @param String $cell\n * @param Integer $value\n * @return NULL\n */\n function setCell($cell, $value) {\n \n }\n \n /**\n * @param String $cell\n * @return NULL\n */\n function resetCell($cell) {\n \n }\n \n /**\n * @param String $formula\n * @return Integer\n */\n function getValue($formula) {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * $obj = Spreadsheet($rows);\n * $obj->setCell($cell, $value);\n * $obj->resetCell($cell);\n * $ret_3 = $obj->getValue($formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Swift",
"langSlug": "swift",
"code": "\nclass Spreadsheet {\n\n init(_ rows: Int) {\n \n }\n \n func setCell(_ cell: String, _ value: Int) {\n \n }\n \n func resetCell(_ cell: String) {\n \n }\n \n func getValue(_ formula: String) -> Int {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * let obj = Spreadsheet(rows)\n * obj.setCell(cell, value)\n * obj.resetCell(cell)\n * let ret_3: Int = obj.getValue(formula)\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Kotlin",
"langSlug": "kotlin",
"code": "class Spreadsheet(rows: Int) {\n\n fun setCell(cell: String, value: Int) {\n \n }\n\n fun resetCell(cell: String) {\n \n }\n\n fun getValue(formula: String): Int {\n \n }\n\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * var obj = Spreadsheet(rows)\n * obj.setCell(cell,value)\n * obj.resetCell(cell)\n * var param_3 = obj.getValue(formula)\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Dart",
"langSlug": "dart",
"code": "class Spreadsheet {\n\n Spreadsheet(int rows) {\n \n }\n \n void setCell(String cell, int value) {\n \n }\n \n void resetCell(String cell) {\n \n }\n \n int getValue(String formula) {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * Spreadsheet obj = Spreadsheet(rows);\n * obj.setCell(cell,value);\n * obj.resetCell(cell);\n * int param3 = obj.getValue(formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Go",
"langSlug": "golang",
"code": "type Spreadsheet struct {\n \n}\n\n\nfunc Constructor(rows int) Spreadsheet {\n \n}\n\n\nfunc (this *Spreadsheet) SetCell(cell string, value int) {\n \n}\n\n\nfunc (this *Spreadsheet) ResetCell(cell string) {\n \n}\n\n\nfunc (this *Spreadsheet) GetValue(formula string) int {\n \n}\n\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * obj := Constructor(rows);\n * obj.SetCell(cell,value);\n * obj.ResetCell(cell);\n * param_3 := obj.GetValue(formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Ruby",
"langSlug": "ruby",
"code": "class Spreadsheet\n\n=begin\n :type rows: Integer\n=end\n def initialize(rows)\n \n end\n\n\n=begin\n :type cell: String\n :type value: Integer\n :rtype: Void\n=end\n def set_cell(cell, value)\n \n end\n\n\n=begin\n :type cell: String\n :rtype: Void\n=end\n def reset_cell(cell)\n \n end\n\n\n=begin\n :type formula: String\n :rtype: Integer\n=end\n def get_value(formula)\n \n end\n\n\nend\n\n# Your Spreadsheet object will be instantiated and called as such:\n# obj = Spreadsheet.new(rows)\n# obj.set_cell(cell, value)\n# obj.reset_cell(cell)\n# param_3 = obj.get_value(formula)",
"__typename": "CodeSnippetNode"
},
{
"lang": "Scala",
"langSlug": "scala",
"code": "class Spreadsheet(_rows: Int) {\n\n def setCell(cell: String, value: Int): Unit = {\n \n }\n\n def resetCell(cell: String): Unit = {\n \n }\n\n def getValue(formula: String): Int = {\n \n }\n\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * val obj = new Spreadsheet(rows)\n * obj.setCell(cell,value)\n * obj.resetCell(cell)\n * val param_3 = obj.getValue(formula)\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Rust",
"langSlug": "rust",
"code": "struct Spreadsheet {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Spreadsheet {\n\n fn new(rows: i32) -> Self {\n \n }\n \n fn set_cell(&self, cell: String, value: i32) {\n \n }\n \n fn reset_cell(&self, cell: String) {\n \n }\n \n fn get_value(&self, formula: String) -> i32 {\n \n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * let obj = Spreadsheet::new(rows);\n * obj.set_cell(cell, value);\n * obj.reset_cell(cell);\n * let ret_3: i32 = obj.get_value(formula);\n */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Racket",
"langSlug": "racket",
"code": "(define spreadsheet%\n (class object%\n (super-new)\n \n ; rows : exact-integer?\n (init-field\n rows)\n \n ; set-cell : string? exact-integer? -> void?\n (define/public (set-cell cell value)\n )\n ; reset-cell : string? -> void?\n (define/public (reset-cell cell)\n )\n ; get-value : string? -> exact-integer?\n (define/public (get-value formula)\n )))\n\n;; Your spreadsheet% object will be instantiated and called as such:\n;; (define obj (new spreadsheet% [rows rows]))\n;; (send obj set-cell cell value)\n;; (send obj reset-cell cell)\n;; (define param_3 (send obj get-value formula))",
"__typename": "CodeSnippetNode"
},
{
"lang": "Erlang",
"langSlug": "erlang",
"code": "-spec spreadsheet_init_(Rows :: integer()) -> any().\nspreadsheet_init_(Rows) ->\n .\n\n-spec spreadsheet_set_cell(Cell :: unicode:unicode_binary(), Value :: integer()) -> any().\nspreadsheet_set_cell(Cell, Value) ->\n .\n\n-spec spreadsheet_reset_cell(Cell :: unicode:unicode_binary()) -> any().\nspreadsheet_reset_cell(Cell) ->\n .\n\n-spec spreadsheet_get_value(Formula :: unicode:unicode_binary()) -> integer().\nspreadsheet_get_value(Formula) ->\n .\n\n\n%% Your functions will be called as such:\n%% spreadsheet_init_(Rows),\n%% spreadsheet_set_cell(Cell, Value),\n%% spreadsheet_reset_cell(Cell),\n%% Param_3 = spreadsheet_get_value(Formula),\n\n%% spreadsheet_init_ will be called before every test case, in which you can do some necessary initializations.",
"__typename": "CodeSnippetNode"
},
{
"lang": "Elixir",
"langSlug": "elixir",
"code": "defmodule Spreadsheet do\n @spec init_(rows :: integer) :: any\n def init_(rows) do\n \n end\n\n @spec set_cell(cell :: String.t, value :: integer) :: any\n def set_cell(cell, value) do\n \n end\n\n @spec reset_cell(cell :: String.t) :: any\n def reset_cell(cell) do\n \n end\n\n @spec get_value(formula :: String.t) :: integer\n def get_value(formula) do\n \n end\nend\n\n# Your functions will be called as such:\n# Spreadsheet.init_(rows)\n# Spreadsheet.set_cell(cell, value)\n# Spreadsheet.reset_cell(cell)\n# param_3 = Spreadsheet.get_value(formula)\n\n# Spreadsheet.init_ will be called before every test case, in which you can do some necessary initializations.",
"__typename": "CodeSnippetNode"
},
{
"lang": "Cangjie",
"langSlug": "cangjie",
"code": "class Spreadsheet {\n init(rows: Int64) {\n\n }\n \n func setCell(cell: String, value: Int64): Unit {\n\n }\n \n func resetCell(cell: String): Unit {\n\n }\n \n func getValue(formula: String): Int64 {\n\n }\n}\n\n/**\n * Your Spreadsheet object will be instantiated and called as such:\n * let obj: Spreadsheet = Spreadsheet(rows)\n * obj.setCell(cell,value)\n * obj.resetCell(cell)\n * let param_3 = obj.getValue(formula)\n */",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.9K\", \"totalSubmission\": \"3.1K\", \"totalAcceptedRaw\": 1855, \"totalSubmissionRaw\": 3129, \"acRate\": \"59.3%\"}",
"hints": [
"Use a hashmap to represent the cells, where the key is the cell reference (e.g., <code>\"A1\"</code>) and the value is the integer stored in the cell.",
"For <code>setCell</code>, simply assign the given value to the specified cell in the hashmap.",
"For <code>resetCell</code>, set the value of the specified cell to <code>0</code> in the hashmap.",
"For <code>getValue</code>, find the values of the operands from the hashmap and return their sum."
],
"solution": null,
"status": null,
"sampleTestCase": "[\"Spreadsheet\",\"getValue\",\"setCell\",\"getValue\",\"setCell\",\"getValue\",\"resetCell\",\"getValue\"]\n[[3],[\"=5+7\"],[\"A1\",10],[\"=A1+6\"],[\"B2\",15],[\"=A1+B2\"],[\"A1\"],[\"=A1+B2\"]]",
"metaData": "{\n \"classname\": \"Spreadsheet\",\n \"constructor\": {\n \"params\": [\n {\n \"type\": \"integer\",\n \"name\": \"rows\"\n }\n ]\n },\n \"methods\": [\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"cell\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"value\"\n }\n ],\n \"name\": \"setCell\",\n \"return\": {\n \"type\": \"void\"\n }\n },\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"cell\"\n }\n ],\n \"name\": \"resetCell\",\n \"return\": {\n \"type\": \"void\"\n }\n },\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"formula\"\n }\n ],\n \"name\": \"getValue\",\n \"return\": {\n \"type\": \"integer\"\n }\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"systemdesign\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
"envInfo": "{\"cpp\":[\"C++\",\"<p>\\u7248\\u672c\\uff1a<code>clang 19<\\/code> \\u91c7\\u7528\\u6700\\u65b0 C++ 23 \\u6807\\u51c6\\uff0c\\u5e76\\u4f7f\\u7528 GCC 14 \\u63d0\\u4f9b\\u7684 <code>libstdc++<\\/code>\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528 <code>-O2<\\/code> \\u7ea7\\u4f18\\u5316\\uff0c\\u5e76\\u63d0\\u4f9b <code>-gline-tables-only<\\/code> \\u53c2\\u6570\\u3002<a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b <code>out-of-bounds<\\/code> \\u548c <code>use-after-free<\\/code> \\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"<p>\\u7248\\u672c\\uff1a<code>OpenJDK 21<\\/code>\\u3002\\u4f7f\\u7528\\u7f16\\u8bd1\\u53c2\\u6570 <code>--enable-preview --release 21<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"<p>\\u7248\\u672c\\uff1a <code>Python 2.7.18<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1a<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>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f Python 2.7 <a href=\\\"https:\\/\\/www.python.org\\/dev\\/peps\\/pep-0373\\/\\\" target=\\\"_blank\\\">\\u5df2\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"c\":[\"C\",\"<p>\\u7248\\u672c\\uff1a<code>GCC 14<\\/code>\\uff0c\\u91c7\\u7528 GNU11 \\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528 <code>-O2<\\/code> \\u7ea7\\u4f18\\u5316\\uff0c\\u5e76\\u63d0\\u4f9b <code>-g1<\\/code> \\u53c2\\u6570\\u3002 <a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b <code>out-of-bounds<\\/code> \\u548c <code>use-after-free<\\/code> \\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u60f3\\u4f7f\\u7528\\u54c8\\u5e0c\\u8868\\u8fd0\\u7b97, \\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/troydhanson.github.io\\/uthash\\/\\\" target=\\\"_blank\\\">uthash<\\/a>\\u3002 \\\"uthash.h\\\"\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5bfc\\u5165\\u3002\\u8bf7\\u770b\\u5982\\u4e0b\\u793a\\u4f8b:<\\/p>\\r\\n\\r\\n<p><b>1. \\u5f80\\u54c8\\u5e0c\\u8868\\u4e2d\\u6dfb\\u52a0\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/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. \\u5728\\u54c8\\u5e0c\\u8868\\u4e2d\\u67e5\\u627e\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/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. \\u4ece\\u54c8\\u5e0c\\u8868\\u4e2d\\u5220\\u9664\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/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-13\\\" target=\\\"_blank\\\">C# 13<\\/a> \\u8fd0\\u884c\\u5728 .NET 9 \\u4e0a<\\/p>\"],\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 22.14.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/v6.3.2\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@6.3.2<\\/a>\\uff0c<a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/v4.2.3\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.3<\\/a> \\u4ee5\\u53ca <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/deque\\/tree\\/v1.0.4\\\" target=\\\"_blank\\\"> datastructures-js\\/deque@1.0.4<\\/a>\\u3002<\\/p>\"],\"ruby\":[\"Ruby\",\"<p>\\u4f7f\\u7528 <code>Ruby 3.2<\\/code> \\u6267\\u884c<\\/p>\\r\\n\\r\\n<p>\\u4e00\\u4e9b\\u5e38\\u7528\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u5df2\\u5728 Algorithms \\u6a21\\u5757\\u4e2d\\u63d0\\u4f9b\\uff1ahttps:\\/\\/www.rubydoc.info\\/github\\/kanwei\\/algorithms\\/Algorithms<\\/p>\"],\"swift\":[\"Swift\",\"<p>\\u7248\\u672c\\uff1a<code>Swift 6.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/apple\\/swift-algorithms\\/tree\\/1.2.0\\\" target=\\\"_blank\\\">swift-algorithms 1.2.0<\\/a>\\uff0c<a href=\\\"https:\\/\\/github.com\\/apple\\/swift-collections\\/tree\\/1.1.4\\\" target=\\\"_blank\\\">swift-collections 1.1.4<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/apple\\/swift-numerics\\/tree\\/1.0.2\\\" target=\\\"_blank\\\">swift-numerics 1.0.2<\\/a><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u901a\\u5e38\\u4fdd\\u8bc1\\u66f4\\u65b0\\u5230 <a href=\\\"https:\\/\\/swift.org\\/download\\/\\\" target=\\\"_blank\\\">Apple\\u653e\\u51fa\\u7684\\u6700\\u65b0\\u7248Swift<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u53d1\\u73b0Swift\\u4e0d\\u662f\\u6700\\u65b0\\u7248\\u7684\\uff0c\\u8bf7\\u8054\\u7cfb\\u6211\\u4eec\\uff01\\u6211\\u4eec\\u5c06\\u5c3d\\u5feb\\u66f4\\u65b0\\u3002<\\/p>\"],\"golang\":[\"Go\",\"<p>\\u7248\\u672c\\uff1a<code>Go 1.23<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 <a href=\\\"https:\\/\\/pkg.go.dev\\/github.com\\/emirpasic\\/gods@v1.18.1\\\" target=\\\"_blank\\\">https:\\/\\/pkg.go.dev\\/github.com\\/emirpasic\\/gods@v1.18.1<\\/a> \\u548c <a href=\\\"https:\\/\\/pkg.go.dev\\/github.com\\/emirpasic\\/gods\\/v2@v2.0.0-alpha\\\" target=\\\"_blank\\\">https:\\/\\/pkg.go.dev\\/github.com\\/emirpasic\\/gods\\/v2@v2.0.0-alpha<\\/a> \\u7b2c\\u4e09\\u65b9\\u5e93\\u3002<\\/p>\"],\"python3\":[\"Python3\",\"<p>\\u7248\\u672c\\uff1a<code>Python 3.11<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982<a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002 \\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u9700\\u4f7f\\u7528 Map\\/TreeMap \\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"http:\\/\\/www.grantjenks.com\\/docs\\/sortedcontainers\\/\\\" target=\\\"_blank\\\">sortedcontainers<\\/a> \\u5e93\\u3002<\\/p>\"],\"scala\":[\"Scala\",\"<p>\\u7248\\u672c\\uff1a<code>Scala 3.3.1<\\/code><\\/p>\"],\"kotlin\":[\"Kotlin\",\"<p>\\u7248\\u672c\\uff1a<code>Kotlin 2.1.10<\\/code><\\/p>\"],\"rust\":[\"Rust\",\"<p>\\u7248\\u672c\\uff1a<code>rust 1.85.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 crates.io \\u7684 <a href=\\\"https:\\/\\/crates.io\\/crates\\/rand\\\" target=\\\"_blank\\\">rand<\\/a>\\u3001<a href=\\\"https:\\/\\/crates.io\\/crates\\/regex\\\" target=\\\"_blank\\\">regex<\\/a> \\u548c <a href=\\\"https:\\/\\/crates.io\\/crates\\/itertools\\\" target=\\\"_blank\\\">itertools<\\/a><\\/p>\"],\"php\":[\"PHP\",\"<p><code>PHP 8.2<\\/code>.<\\/p>\\r\\n\\r\\n<p>With bcmath module.<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.7.3<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2024<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/v6.3.2\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@6.3.2<\\/a>\\uff0c<a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/v4.2.3\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.3<\\/a> \\u4ee5\\u53ca <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/deque\\/tree\\/v1.0.4\\\" target=\\\"_blank\\\"> datastructures-js\\/deque@1.0.4<\\/a>\\u3002<\\/p>\"],\"racket\":[\"Racket\",\"<p><a href=\\\"https:\\/\\/docs.racket-lang.org\\/guide\\/performance.html#%28tech._c%29\\\" target=\\\"_blank\\\">Racket CS<\\/a> v8.15<\\/p>\\r\\n\\r\\n<p>\\u4f7f\\u7528 #lang racket<\\/p>\\r\\n\\r\\n<p>\\u5df2\\u9884\\u5148 (require data\\/gvector data\\/queue data\\/order data\\/heap). \\u82e5\\u9700\\u4f7f\\u7528\\u5176\\u5b83\\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u53ef\\u81ea\\u884c require\\u3002<\\/p>\"],\"erlang\":[\"Erlang\",\"Erlang\\/OTP 26\"],\"elixir\":[\"Elixir\",\"Elixir 1.17 with Erlang\\/OTP 26\"],\"dart\":[\"Dart\",\"<p>Dart 3.2\\u3002\\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/pub.dev\\/packages\\/collection\\/versions\\/1.18.0\\\" target=\\\"_blank\\\">collection<\\/a> \\u5305<\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5c06\\u4f1a\\u88ab\\u4e0d\\u7f16\\u8bd1\\u76f4\\u63a5\\u8fd0\\u884c<\\/p>\"],\"cangjie\":[\"Cangjie\",\"<p>\\u7248\\u672c\\uff1a0.53.11 (cjnative)<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u53c2\\u6570\\uff1a<code>-O2 --disable-reflection<\\/code><\\/p>\\r\\n\\r\\n<p>\\u5feb\\u901f\\u5165\\u95e8\\u8bf7\\u67e5\\u9605<a href=\\\"https:\\/\\/leetcode.cn\\/leetbook\\/detail\\/cangjie\\/\\\" target=\\\"_blank\\\">\\u300c\\u4ed3\\u9889\\u7f16\\u7a0b\\u8bed\\u8a00\\u5f00\\u53d1\\u6307\\u5357\\u300d<\\/a><\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "[\"Spreadsheet\",\"getValue\",\"setCell\",\"getValue\",\"setCell\",\"getValue\",\"resetCell\",\"getValue\"]\n[[3],[\"=5+7\"],[\"A1\",10],[\"=A1+6\"],[\"B2\",15],[\"=A1+B2\"],[\"A1\"],[\"=A1+B2\"]]",
"__typename": "QuestionNode"
}
}
}