From b36cba6f38835fe9cd77c9adb88a7d26b29cf8fd Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:54:13 +0530 Subject: [PATCH 1/2] Update README.md --- .../2700-2799/2751.Robot Collisions/README.md | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/solution/2700-2799/2751.Robot Collisions/README.md b/solution/2700-2799/2751.Robot Collisions/README.md index ed0bb46be82ec..0f8fb742950e7 100644 --- a/solution/2700-2799/2751.Robot Collisions/README.md +++ b/solution/2700-2799/2751.Robot Collisions/README.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 601f7e1636a1925e21e7be39109e12d1263168d9 Mon Sep 17 00:00:00 2001 From: Yashwanth137 Date: Sat, 13 Jul 2024 16:25:08 +0000 Subject: [PATCH 2/2] style: format code and docs with prettier --- solution/2700-2799/2751.Robot Collisions/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/2700-2799/2751.Robot Collisions/README.md b/solution/2700-2799/2751.Robot Collisions/README.md index 0f8fb742950e7..cc610c08b8937 100644 --- a/solution/2700-2799/2751.Robot Collisions/README.md +++ b/solution/2700-2799/2751.Robot Collisions/README.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] ```