#3484
Design Spreadsheet
pupil · 510 · lc medium +27 · 74.3% accepted · 326 likes · top 85%
Description
Build a Spreadsheet class representing a grid with 26 columns (\'A\' through \'Z\') and a configurable number of rows. Cells hold integers from 0 to 105.
Implement:
- Spreadsheet(int rows): Creates the spreadsheet with all cells initialized to 0.
- void setCell(String cell, int value): Assigns a value to the cell identified by column letter and 1-indexed row (e.g., "A1", "B10").
- void resetCell(String cell): Sets the specified cell back to 0.
- int getValue(String formula): Evaluates a formula "=X+Y" where X and Y are cell references or non-negative integers, returning their sum.
Unset cells are treated as 0 when referenced by getValue.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20