aboutsummaryrefslogtreecommitdiffstats
path: root/leetcode/2833/main.c
blob: 1e17eb04e8c07fe69f03e2c4e5cdf1ad8a80fbbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdlib.h>
#include <string.h>

int furthestDistanceFromOrigin(char *moves) {
    int len = strlen(moves);
    int L = 0;
    int R = 0;
    int B = 0;

    for (int i = 0; i < len; i++) {
        if (moves[i] == 'L') {
            L++;
        } else if (moves[i] == 'R') {
            R++;
        } else {
            B++;
        }
    }

    return abs(L - R) + B;
}