Skip to content

Latest commit

 

History

History
54 lines (48 loc) · 1.23 KB

657 Robot Return to Origin 5975dcf388cf4ca1834b1816969d839c.md

File metadata and controls

54 lines (48 loc) · 1.23 KB

657. Robot Return to Origin

LeetCode - The World's Leading Online Programming Learning Platform

class Solution {
    public boolean judgeCircle(String moves) {
        int UpDown = 0;
        int LeftRight = 0;

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

        for (char c : moves.toCharArray() )
        {
            switch (c){
                case 'U':
                    UpDown++;
                    break;
                case 'D':
                    UpDown--;
                    break;
                case 'L':
                    LeftRight++;
                    break;
                case 'R':
                    LeftRight--;
                    break;
            }
        }

        return (LeftRight == 0 && UpDown == 0); 
    }
}