Untitled
unknown
plain_text
a year ago
539 B
33
Indexable
class Solution {
public:
int finalPositionOfSnake(int n, vector<string>& commands) {
int x = 0, y = 0;
for(int i = 0 ; i < commands.size() ; i++){
if(commands[i] == "UP"){
x--;
}
else if(commands[i] == "RIGHT"){
y++;
}
else if(commands[i] == "DOWN"){
x++;
}
else if(commands[i] == "LEFT"){
y--;
}
}
return (x*n + y);
}
};Editor is loading...
Leave a Comment