Skip to content

Commit 7e1a420

Browse files
authored
feat: add solution to lc problem: No.3484 (doocs#4731)
1 parent 96c0036 commit 7e1a420

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

solution/3400-3499/3484.Design Spreadsheet/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,42 @@ impl Spreadsheet {
312312
}
313313
```
314314

315+
#### C#
316+
317+
```cs
318+
public class Spreadsheet {
319+
private Dictionary<string, int> d = new Dictionary<string, int>();
320+
321+
public Spreadsheet(int rows) {
322+
}
323+
324+
public void SetCell(string cell, int value) {
325+
d[cell] = value;
326+
}
327+
328+
public void ResetCell(string cell) {
329+
d.Remove(cell);
330+
}
331+
332+
public int GetValue(string formula) {
333+
int ans = 0;
334+
foreach (string cell in formula.Substring(1).Split('+')) {
335+
ans += char.IsDigit(cell[0]) ? int.Parse(cell)
336+
: (d.ContainsKey(cell) ? d[cell] : 0);
337+
}
338+
return ans;
339+
}
340+
}
341+
342+
/**
343+
* Your Spreadsheet object will be instantiated and called as such:
344+
* Spreadsheet obj = new Spreadsheet(rows);
345+
* obj.SetCell(cell,value);
346+
* obj.ResetCell(cell);
347+
* int param_3 = obj.GetValue(formula);
348+
*/
349+
```
350+
315351
<!-- tabs:end -->
316352

317353
<!-- solution:end -->

solution/3400-3499/3484.Design Spreadsheet/README_EN.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,42 @@ impl Spreadsheet {
310310
}
311311
```
312312

313+
#### C#
314+
315+
```cs
316+
public class Spreadsheet {
317+
private Dictionary<string, int> d = new Dictionary<string, int>();
318+
319+
public Spreadsheet(int rows) {
320+
}
321+
322+
public void SetCell(string cell, int value) {
323+
d[cell] = value;
324+
}
325+
326+
public void ResetCell(string cell) {
327+
d.Remove(cell);
328+
}
329+
330+
public int GetValue(string formula) {
331+
int ans = 0;
332+
foreach (string cell in formula.Substring(1).Split('+')) {
333+
ans += char.IsDigit(cell[0]) ? int.Parse(cell)
334+
: (d.ContainsKey(cell) ? d[cell] : 0);
335+
}
336+
return ans;
337+
}
338+
}
339+
340+
/**
341+
* Your Spreadsheet object will be instantiated and called as such:
342+
* Spreadsheet obj = new Spreadsheet(rows);
343+
* obj.SetCell(cell,value);
344+
* obj.ResetCell(cell);
345+
* int param_3 = obj.GetValue(formula);
346+
*/
347+
```
348+
313349
<!-- tabs:end -->
314350

315351
<!-- solution:end -->
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class Spreadsheet {
2+
private Dictionary<string, int> d = new Dictionary<string, int>();
3+
4+
public Spreadsheet(int rows) {
5+
}
6+
7+
public void SetCell(string cell, int value) {
8+
d[cell] = value;
9+
}
10+
11+
public void ResetCell(string cell) {
12+
d.Remove(cell);
13+
}
14+
15+
public int GetValue(string formula) {
16+
int ans = 0;
17+
foreach (string cell in formula.Substring(1).Split('+')) {
18+
ans += char.IsDigit(cell[0]) ? int.Parse(cell)
19+
: (d.ContainsKey(cell) ? d[cell] : 0);
20+
}
21+
return ans;
22+
}
23+
}
24+
25+
/**
26+
* Your Spreadsheet object will be instantiated and called as such:
27+
* Spreadsheet obj = new Spreadsheet(rows);
28+
* obj.SetCell(cell,value);
29+
* obj.ResetCell(cell);
30+
* int param_3 = obj.GetValue(formula);
31+
*/

0 commit comments

Comments
 (0)