From 342e23a2947b52e4f795b0de7c6823ded628d16d Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Fri, 19 Sep 2025 06:54:25 +0800 Subject: [PATCH] feat: add solution to lc problem: No.3484 --- .../3484.Design Spreadsheet/README.md | 36 +++++++++++++++++++ .../3484.Design Spreadsheet/README_EN.md | 36 +++++++++++++++++++ .../3484.Design Spreadsheet/Solution.cs | 31 ++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 solution/3400-3499/3484.Design Spreadsheet/Solution.cs diff --git a/solution/3400-3499/3484.Design Spreadsheet/README.md b/solution/3400-3499/3484.Design Spreadsheet/README.md index 21ec3f99602f7..ba2fc0d592882 100644 --- a/solution/3400-3499/3484.Design Spreadsheet/README.md +++ b/solution/3400-3499/3484.Design Spreadsheet/README.md @@ -312,6 +312,42 @@ impl Spreadsheet { } ``` +#### C# + +```cs +public class Spreadsheet { + private Dictionary d = new Dictionary(); + + public Spreadsheet(int rows) { + } + + public void SetCell(string cell, int value) { + d[cell] = value; + } + + public void ResetCell(string cell) { + d.Remove(cell); + } + + public int GetValue(string formula) { + int ans = 0; + foreach (string cell in formula.Substring(1).Split('+')) { + ans += char.IsDigit(cell[0]) ? int.Parse(cell) + : (d.ContainsKey(cell) ? d[cell] : 0); + } + return ans; + } +} + +/** + * Your Spreadsheet object will be instantiated and called as such: + * Spreadsheet obj = new Spreadsheet(rows); + * obj.SetCell(cell,value); + * obj.ResetCell(cell); + * int param_3 = obj.GetValue(formula); + */ +``` + diff --git a/solution/3400-3499/3484.Design Spreadsheet/README_EN.md b/solution/3400-3499/3484.Design Spreadsheet/README_EN.md index 57ae6bf843f4e..106261b730930 100644 --- a/solution/3400-3499/3484.Design Spreadsheet/README_EN.md +++ b/solution/3400-3499/3484.Design Spreadsheet/README_EN.md @@ -310,6 +310,42 @@ impl Spreadsheet { } ``` +#### C# + +```cs +public class Spreadsheet { + private Dictionary d = new Dictionary(); + + public Spreadsheet(int rows) { + } + + public void SetCell(string cell, int value) { + d[cell] = value; + } + + public void ResetCell(string cell) { + d.Remove(cell); + } + + public int GetValue(string formula) { + int ans = 0; + foreach (string cell in formula.Substring(1).Split('+')) { + ans += char.IsDigit(cell[0]) ? int.Parse(cell) + : (d.ContainsKey(cell) ? d[cell] : 0); + } + return ans; + } +} + +/** + * Your Spreadsheet object will be instantiated and called as such: + * Spreadsheet obj = new Spreadsheet(rows); + * obj.SetCell(cell,value); + * obj.ResetCell(cell); + * int param_3 = obj.GetValue(formula); + */ +``` + diff --git a/solution/3400-3499/3484.Design Spreadsheet/Solution.cs b/solution/3400-3499/3484.Design Spreadsheet/Solution.cs new file mode 100644 index 0000000000000..e01b30e25d7af --- /dev/null +++ b/solution/3400-3499/3484.Design Spreadsheet/Solution.cs @@ -0,0 +1,31 @@ +public class Spreadsheet { + private Dictionary d = new Dictionary(); + + public Spreadsheet(int rows) { + } + + public void SetCell(string cell, int value) { + d[cell] = value; + } + + public void ResetCell(string cell) { + d.Remove(cell); + } + + public int GetValue(string formula) { + int ans = 0; + foreach (string cell in formula.Substring(1).Split('+')) { + ans += char.IsDigit(cell[0]) ? int.Parse(cell) + : (d.ContainsKey(cell) ? d[cell] : 0); + } + return ans; + } +} + +/** + * Your Spreadsheet object will be instantiated and called as such: + * Spreadsheet obj = new Spreadsheet(rows); + * obj.SetCell(cell,value); + * obj.ResetCell(cell); + * int param_3 = obj.GetValue(formula); + */