Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-12-12_23-53-03.png
34.8 KB
#N657. Robot Return to Origin
problem link

#solution
class Solution {
public boolean judgeCircle(String moves) {
int[] count = new int[4];

for(char ch: moves.toCharArray()){
if(ch == 'R') count[0]++;
else if(ch == 'L') count[1]++;
else if(ch == 'U') count[2]++;
else count[3]++;
}

return count[0] - count[1] == 0 && count[2] - count[3] == 0;
}
}