From 82cd6e489459ac76a445f7be347baf5a505e4d55 Mon Sep 17 00:00:00 2001 From: Qiming Xu <458173774@qq.com> Date: Mon, 22 Jan 2024 00:30:21 +0000 Subject: [PATCH] leetcode: finished #735 --- content/leetcode/2024/1.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/content/leetcode/2024/1.md b/content/leetcode/2024/1.md index 3f5df5ac..b653e48b 100644 --- a/content/leetcode/2024/1.md +++ b/content/leetcode/2024/1.md @@ -3,6 +3,36 @@ title: 2024.1 draft: false --- +# 2024.1.22 + +```python +# +# @lc app=leetcode.cn id=735 lang=python3 +# +# [735] 小行星碰撞 +# + + +# @lc code=start +class Solution: + def asteroidCollision(self, asteroids: List[int]) -> List[int]: + stack = [] + for a in asteroids: + while stack and a < 0 < stack[-1]: + if stack[-1] < -a: + stack.pop() + continue + elif stack[-1] == -a: + stack.pop() + break + else: + stack.append(a) + return stack + + +# @lc code=end +``` + # 2024.1.21 ```python