defsolution(num, data): # Please write your code here ans = [] # 状态数组,左为负,右为正 weight = [0for _ inrange(num)] # 初始化 for i, state inenumerate(data): if state == 'L': weight[i] = -1 elif state == 'R': weight[i] = 1 # 得出num天的状态 for i inrange(1, num): for obj inrange(0, num): # 右倾倒 if weight[obj] == i and obj != num-1and weight[obj+1] == 0: weight[obj+1] = i+1 # 左倾倒 elif weight[obj] == -i and obj != 0: # 相同数量右倾倒和左倾倒,力平衡 if weight[obj-1] != 0and weight[obj-1] == i+1: weight[obj-1] = 0 elif weight[obj-1] == 0: weight[obj-1] = -i-1
for i inrange(num): if weight[i] == 0: ans.append(i+1)
iflen(ans) == 0: return"0" result = str(len(ans))+":" result += ",".join(map(str, ans)) return result
if __name__ == "__main__": # You can add more test cases here print(solution(14, ".L.R...LR..L..") == "4:3,6,13,14" ) print(solution(5, "R....") == "0" ) print(solution(1, ".") == "1:1" )