From 7d0bc7f60f0347a09a1ad3c2cb82cfd90f0f65f2 Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:55:30 +0530 Subject: [PATCH 1/2] Update README_EN.md --- .../2751.Robot Collisions/README_EN.md | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/solution/2700-2799/2751.Robot Collisions/README_EN.md b/solution/2700-2799/2751.Robot Collisions/README_EN.md index f624b21067c2e..4bf8202571caa 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 From 30a987a59e3e5393444441e4655b9cc29e318f3f Mon Sep 17 00:00:00 2001 From: Yashwanth137 Date: Sat, 13 Jul 2024 16:26:31 +0000 Subject: [PATCH 2/2] style: format code and docs with prettier --- solution/2700-2799/2751.Robot Collisions/README_EN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/2700-2799/2751.Robot Collisions/README_EN.md b/solution/2700-2799/2751.Robot Collisions/README_EN.md index 4bf8202571caa..4546b08b09cf8 100644 --- a/solution/2700-2799/2751.Robot Collisions/README_EN.md +++ b/solution/2700-2799/2751.Robot Collisions/README_EN.md @@ -112,7 +112,7 @@ class Solution: stack.append(j) else: healths[i] = healths[j] = 0 - + return [item for item in healths if item > 0] ```