0631. Design Excel Sum Formula
https://leetcode.com/problems/design-excel-sum-formula
Description
Design the basic function of Excel and implement the function of the sum formula.
Implement the Excel
class:
Excel(int height, char width)
Initializes the object with theheight
and thewidth
of the sheet. The sheet is an integer matrixmat
of sizeheight x width
with the row index in the range[1, height]
and the column index in the range['A', width]
. All the values should be zero initially.void set(int row, char column, int val)
Changes the value atmat[row][column]
to beval
.int get(int row, char column)
Returns the value atmat[row][column]
.int sum(int row, char column, List<String> numbers)
Sets the value atmat[row][column]
to be the sum of cells represented bynumbers
and returns the value atmat[row][column]
. This sum formula should exist until this cell is overlapped by another value or another sum formula.numbers[i]
could be on the format:"ColRow"
that represents a single cell.For example,
"F7"
represents the cellmat[7]['F']
.
"ColRow1:ColRow2"
that represents a range of cells. The range will always be a rectangle where"ColRow1"
represent the position of the top-left cell, and"ColRow2"
represents the position of the bottom-right cell.For example,
"B3:F7"
represents the cellsmat[i][j]
for3 <= i <= 7
and'B' <= j <= 'F'
.
Note: You could assume that there will not be any circular sum reference.
For example,
mat[1]['A'] == sum(1, "B")
andmat[1]['B'] == sum(1, "A")
.
Example 1:
Constraints:
1 <= height <= 26
'A' <= width <= 'Z'
1 <= row <= height
'A' <= column <= width
-100 <= val <= 100
1 <= numbers.length <= 5
numbers[i]
has the format"ColRow"
or"ColRow1:ColRow2"
.At most
100
calls will be made toset
,get
, andsum
.
ac
Last updated