解法一
分别统计水平和竖直方向上移动的距离,均为0则返回原点。
class Solution {public boolean judgeCircle(String moves) {int x = 0, y = 0;for (int i = 0; i < moves.length(); ++i) {switch (moves.charAt(i)) {case 'R':++x;break;case 'L':--x;break;case 'U':++y;break;case 'D':--y;break;}}if ((x == 0) && (y == 0)) {return true;} else {return false;}}}
