1class Solution {2public:3bool isRobotBounded(string instructions) {4char direction = 'N';5int x = 0, y = 0;6for (char &instruction : instructions) {7if (instruction == 'G') {8if (direction == 'N')9y++;10else if (direction == 'S')11y--;12else if (direction == 'W')13x--;14else15x++;16} else if (instruction == 'L') {17if (direction == 'N')18direction = 'W';19else if (direction == 'S')20direction = 'E';21else if (direction == 'W')22direction = 'S';23else24direction = 'N';25} else {26if (direction == 'N')27direction = 'E';28else if (direction == 'S')29direction = 'W';30else if (direction == 'W')31direction = 'N';32else33direction = 'S';34}35}36return (x == 0 && y == 0) || direction != 'N';37}38};