Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def lineUp(commands)
- number = 0
- lr_combinations = 0
- x = 1
- if commands.length == 0 then
- return 0
- end
- if commands.length == 1 and commands == 'A' then
- return 1
- end
- if commands.length == 1 and (commands == 'L' or commands == 'R') then
- return 0
- end
- if commands[0] == 'A' then
- number = number + 1
- end
- if commands[0] == 'L' or commands[0] == 'R' then
- lr_combinations = lr_combinations + 1
- end
- while (x < commands.length)
- if (commands[x] == 'L' or commands[x] == 'R') and (commands[x - 1] == 'L' or commands[x - 1] == 'R') then
- lr_combinations = lr_combinations + 1
- if lr_combinations % 2 == 0 then
- number = number + 1
- end
- end
- if (commands[x] == 'L' or commands[x] == 'R') and (commands[x - 1] == 'A') then
- lr_combinations = lr_combinations + 1
- if lr_combinations % 2 == 0 then
- number = number + 1
- end
- end
- if commands[x] == 'A' and lr_combinations == 0 then
- number = number + 1
- end
- if lr_combinations != 0 then
- if commands[x] == 'A' and lr_combinations % 2 == 0 then
- number = number + 1
- end
- end
- x = x + 1
- end
- return number
- end
Advertisement
Add Comment
Please, Sign In to add comment