LeetCode solutions

2304. Cells in a Range on an Excel Sheet

My accepted Python solution to LeetCode problem 2304, Cells in a Range on an Excel Sheet, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-29.

python
class Solution:
    def cellsInRange(self, s: str) -> List[str]:
        col1, row1, col2, row2 = s[0], int(s[1]), s[3], int(s[4])
        result = []
        
        for col in range(ord(col1), ord(col2) + 1):
            for row in range(row1, row2 + 1):
                result.append(chr(col) + str(row))
        
        return result

Source