0
点赞
收藏
分享

微信扫一扫

[leetcode]657. Judge Route Circle

_鱼与渔_ 2023-03-23 阅读 55


the original place.

R (Right), L(Left), U (Up) and D

Example 1:

Input: "UD"
Output: true

Example 2:

Input: "LL"
Output: false



class Solution {
    public boolean judgeCircle(String moves) {
        int x = 0;
        int y = 0;
        for (int i = 0; i < moves.length(); i++) {
            char c = moves.charAt(i);
            switch (c) {
                case 'U':
                    y++;
                    break;
                case 'D':
                    y--;
                    break;
                case 'R':
                    x++;
                    break;
                case 'L':
                    x--;
                    break;
                default:
                    break;
            }
        }
        return x == 0 && y == 0;
    }
}




举报

相关推荐

0 条评论