Time: 2 ms (52.81%), Space: 17.7 MB (77.55%) - LeetHub

This commit is contained in:
Deven
2025-03-04 17:11:20 -05:00
parent 2f8823ca54
commit 6c8ff95583
@@ -0,0 +1,12 @@
class Solution:
def finalPositionOfSnake(self, n: int, commands: List[str]) -> int:
movesCount = {
"RIGHT": 0,
"LEFT": 0,
"UP": 0,
"DOWN": 0,
}
for command in commands:
movesCount[command] += 1
return movesCount["RIGHT"] - movesCount["LEFT"] + n * (movesCount["DOWN"] - movesCount["UP"])