clueless coding // TODO: be smarter

LeetCode Judge Route Circle: CPP Solution



TL;DR Code Solution


bool judgeCircle(string moves) {
    int horizontal = 0;
    int vertical = 0;

    for (int i = 0; i < moves.length(); i++) {
        switch(moves[i]) {
            case 'U':
                vertical++;
                break;
            case 'D':
                vertical--;;
                break;
            case 'R':
                horizontal++;
                break;
            case 'L':
                horizontal--;
                break;
        }
    }

    return horizontal == 0 && vertical == 0;

}