Skip to content

Commit 4ee8916

Browse files
solves #2194: Cells in a Range on an Excel Sheet in java
1 parent 1cdbba7 commit 4ee8916

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@
717717
| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
718718
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | |
719719
| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | |
720-
| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | |
720+
| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | |
721721
| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | |
722722
| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | | |
723723
| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | | |

Diff for: src/CellsInARangeOnAnExcelSheet.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet
2+
// T: O(1)
3+
// S: O(1)
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class CellsInARangeOnAnExcelSheet {
9+
public List<String> cellsInRange(String s) {
10+
final char column1 = s.charAt(0);
11+
final char column2 = s.charAt(3);
12+
final int row1 = s.charAt(1) - '0';
13+
final int row2 = s.charAt(4) - '0';
14+
15+
final List<String> result = new ArrayList<>();
16+
17+
for (char column = column1 ; column <= column2 ; column++) {
18+
for (int row = row1 ; row <= row2 ; row++) {
19+
result.add((column + "") + row);
20+
}
21+
}
22+
23+
return result;
24+
}
25+
}

0 commit comments

Comments
 (0)