MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / robot

Method robot

Java/Leetcode/Leetcode657.java:10–34  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

8
9
10 static boolean robot(String s){
11 int l=0,r=0,u=0,d=0;
12 for (int i = 0; i < s.length(); i++) {
13 char ch=s.charAt(i);
14 if(ch=='L' || ch=='l'){
15 l++;
16 }
17 if(ch=='R' ||ch=='r' ){
18 r++;
19 }
20 if(ch=='U' || ch=='u'){
21 u++;
22 }
23 if(ch=='D' ||ch=='d' ){
24 d++;
25 }
26 }
27
28 if(l==r && u==d){
29 return true;
30 }
31 else{
32 return false;
33 }
34 }
35}

Callers 1

mainMethod · 0.95

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected