Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1005 Bytes

_3248. Snake in Matrix.md

File metadata and controls

44 lines (32 loc) · 1005 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : August 12, 2024

Last updated : August 12, 2024


Related Topics : Array, String, Simulation

Acceptance Rate : 82.45 %


Solutions

Python

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