Robot Return to Origin

Robot在(0,0)点, 给UP DOWN LEFT RIGHT几个操作, 问最后是不是回到原点. 直接模拟一下就可以.

class Solution {
    public boolean judgeCircle(String moves) {
        int x = 0;
        int y = 0;
        for(char c : moves.toCharArray()) {
            if(c == 'U')
                y++;
            else if(c == 'D')
                y--;
            else if(c == 'R')
                x++;
            else
                x--;
        }
        return (x == 0 && y == 0);
    }
}