Skip to content

Commit f297078

Browse files
authored
Merge pull request neetcode-gh#3296 from AmitSaha15/main
Create 1041-robot-bounded-in-circle.java
2 parents d5d67b5 + 76c3fa4 commit f297078

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public boolean isRobotBounded(String instructions) {
3+
int x=0, y=0;
4+
int dirX = 0, dirY=1;
5+
6+
for(char ch : instructions.toCharArray()){
7+
if(ch == 'G'){
8+
x += dirX;
9+
y += dirY;
10+
} else if(ch == 'L'){
11+
int temp = dirX;
12+
dirX = -1*dirY;
13+
dirY = temp;
14+
} else{
15+
int temp = dirX;
16+
dirX = dirY;
17+
dirY = -1*temp;
18+
}
19+
}
20+
21+
return (x==0 && y==0) || (dirX!=0 || dirY!=1);
22+
}
23+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy