Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions solution/3400-3499/3484.Design Spreadsheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,42 @@ impl Spreadsheet {
}
```

#### C#

```cs
public class Spreadsheet {
private Dictionary<string, int> d = new Dictionary<string, int>();

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);
*/
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
36 changes: 36 additions & 0 deletions solution/3400-3499/3484.Design Spreadsheet/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,42 @@ impl Spreadsheet {
}
```

#### C#

```cs
public class Spreadsheet {
private Dictionary<string, int> d = new Dictionary<string, int>();

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);
*/
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
31 changes: 31 additions & 0 deletions solution/3400-3499/3484.Design Spreadsheet/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Spreadsheet {
private Dictionary<string, int> d = new Dictionary<string, int>();

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);
*/