3248. Snake in Matrix
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : August 12, 2024
Last updated : August 12, 2024
Related Topics : Array, String, Simulation
Acceptance Rate : 82.45 %
class Solution:
def finalPositionOfSnake(self, n: int, commands: List[str]) -> int:
x, y = 0, 0
for c in commands :
match c :
case 'DOWN' :
y += 1
case 'UP' :
y -= 1
case 'LEFT' :
x -= 1
case _ :
x += 1
return y * n + x