3484. Design Spreadsheet Medium

@problem@discussion
#Array#Hash Table#String#Design#Matrix



1/**
2 * [3484] Design Spreadsheet
3 *
4 * A spreadsheet is a grid with 26 columns (labeled from 'A' to 'Z') and a given number of rows. Each cell in the spreadsheet can hold an integer value between 0 and 10^5.
5 * Implement the Spreadsheet class:
6 * 
7 * 	Spreadsheet(int rows) Initializes a spreadsheet with 26 columns (labeled 'A' to 'Z') and the specified number of rows. All cells are initially set to 0.
8 * 	void setCell(String cell, int value) Sets the value of the specified cell. The cell reference is provided in the format "AX" (e.g., "A1", "B10"), where the letter represents the column (from 'A' to 'Z') and the number represents a 1-indexed row.
9 * 	void resetCell(String cell) Resets the specified cell to 0.
10 * 	int getValue(String formula) Evaluates a formula of the form "=X+Y", where X and Y are either cell references or non-negative integers, and returns the computed sum.
11 * 
12 * Note: If getValue references a cell that has not been explicitly set using setCell, its value is considered 0.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input:<br />
17 * <span class="example-io">["Spreadsheet", "getValue", "setCell", "getValue", "setCell", "getValue", "resetCell", "getValue"]<br />
18 * [[3], ["=5+7"], ["A1", 10], ["=A1+6"], ["B2", 15], ["=A1+B2"], ["A1"], ["=A1+B2"]]</span>
19 * Output:<br />
20 * <span class="example-io">[null, 12, null, 16, null, 25, null, 15] </span>
21 * Explanation
22 * Spreadsheet spreadsheet = new Spreadsheet(3); // Initializes a spreadsheet with 3 rows and 26 columns<br data-end="321" data-start="318" />
23 * spreadsheet.getValue("=5+7"); // returns 12 (5+7)<br data-end="373" data-start="370" />
24 * spreadsheet.setCell("A1", 10); // sets A1 to 10<br data-end="423" data-start="420" />
25 * spreadsheet.getValue("=A1+6"); // returns 16 (10+6)<br data-end="477" data-start="474" />
26 * spreadsheet.setCell("B2", 15); // sets B2 to 15<br data-end="527" data-start="524" />
27 * spreadsheet.getValue("=A1+B2"); // returns 25 (10+15)<br data-end="583" data-start="580" />
28 * spreadsheet.resetCell("A1"); // resets A1 to 0<br data-end="634" data-start="631" />
29 * spreadsheet.getValue("=A1+B2"); // returns 15 (0+15)</div>
30 *  
31 * Constraints:
32 * 
33 * 	1 <= rows <= 10^3
34 * 	0 <= value <= 10^5
35 * 	The formula is always in the format "=X+Y", where X and Y are either valid cell references or non-negative integers with values less than or equal to 10^5.
36 * 	Each cell reference consists of a capital letter from 'A' to 'Z' followed by a row number between 1 and rows.
37 * 	At most 10^4 calls will be made in total to setCell, resetCell, and getValue.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/design-spreadsheet/
43// discuss: https://leetcode.com/problems/design-spreadsheet/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47struct Spreadsheet {
48        false
49    }
50
51
52/** 
53 * `&self` means the method takes an immutable reference.
54 * If you need a mutable reference, change it to `&mut self` instead.
55 */
56impl Spreadsheet {
57
58    fn new(rows: i32) -> Self {
59        
60    }
61    
62    fn set_cell(&self, cell: String, value: i32) {
63        
64    }
65    
66    fn reset_cell(&self, cell: String) {
67        
68    }
69    
70    fn get_value(&self, formula: String) -> i32 {
71        
72    }
73}
74
75/**
76 * Your Spreadsheet object will be instantiated and called as such:
77 * let obj = Spreadsheet::new(rows);
78 * obj.set_cell(cell, value);
79 * obj.reset_cell(cell);
80 * let ret_3: i32 = obj.get_value(formula);
81 */
82
83// submission codes end
84
85#[cfg(test)]
86mod tests {
87    use super::*;
88
89    #[test]
90    fn test_3484() {
91    }
92}
93

Back
© 2026 bowen.ge All Rights Reserved.