Java solution


  • 0
    D

    class Solution {
    public boolean judgeCircle(String moves) {
    int h = 0;
    int v = 0;
    for (int i = 0; i < moves.length(); i++) {
    if (moves.charAt(i) == 'L') h++;
    else if (moves.charAt(i) == 'R') h--;
    else if (moves.charAt(i) == 'U') v++;
    else if (moves.charAt(i) == 'D') v--;
    }
    return h == 0 && v == 0;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.