12 May 2017

Lineup

My solution:
int lineUp(string commands) 
{
    var b = true;
    var count = 0;
    foreach (var c in commands)
        if ((c == 'L' || c == 'R') && b)
            b = false;
        else if ((c == 'L' || c == 'R') && !b)
        {
            b = true;
            count++;
        }
        else if (c == 'A')
            if (b)
                count++;

    return count;
}

Previous Next