diff --git a/solution/2700-2799/2751.Robot Collisions/README_EN.md b/solution/2700-2799/2751.Robot Collisions/README_EN.md index f624b21067c2e..4546b08b09cf8 100644 --- a/solution/2700-2799/2751.Robot Collisions/README_EN.md +++ b/solution/2700-2799/2751.Robot Collisions/README_EN.md @@ -90,7 +90,30 @@ tags: #### Python3 ```python - +class Solution: + def survivedRobotsHealths(self, positions: List[int], healths: List[int], directions: str) -> List[int]: + temp = {x: i for i,x in enumerate(positions)} + + stack = [] + for x in sorted(positions): + i = temp[x] + + if directions[i] == "R": + stack.append(i) + else: + while stack and healths[i]: + j = stack.pop() + if healths[i] > healths[j]: + healths[j] = 0 + healths[i] -= 1 + elif healths[i] < healths[j]: + healths[i] = 0 + healths[j] -= 1 + stack.append(j) + else: + healths[i] = healths[j] = 0 + + return [item for item in healths if item > 0] ``` #### Java