Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 587 Bytes

File metadata and controls

28 lines (24 loc) · 587 Bytes

LeetCode Records - Question 657 Robot Return to Origin

Attempt 1:

class Solution {
    public boolean judgeCircle(String moves) {
        int x = 0, y = 0;

        for (char ch : moves.toCharArray()) {
            if (ch == 'U') {
                y++;
            } else if (ch == 'D') {
                y--;
            } else if (ch == 'L') {
                x--;
            } else {
                x++;
            }
        }

        return x == 0 && y == 0;
    }
}
  • Runtime: 4 ms (Beats: 97.65%)
  • Memory: 44.16 MB (Beats: 82.91%)