일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 쓰릴오브파이트
- FIT XR
- English
- 미드시청
- 뭐든
- 30분
- 운동
- 3줄정리
- 화상영어
- Problem Solving
- 읽기
- 링피트
- 잡생각
- 파비최
- leetcode
- 월간
- 사이드
- 10분
- 스탭퍼
- 프로젝트
- 리얼 클래스
- 영어공부
- 영어원서읽기
- 만화도
- 괜찮음
- realclass
- Daily Challenge
- Writing
- 개발자
- 매일
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.07.20 Today's Challenge 본문
https://leetcode.com/problems/asteroid-collision/
Asteroid Collision - LeetCode
Can you solve this real interview question? Asteroid Collision - We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning
leetcode.com
소행성 충돌하는 로직을 구하는 문제
class Solution:
def asteroidCollision(self, asteroids: List[int]) -> List[int]:
st = []
for a in asteroids:
if not st or a > 0:
st.append (a)
else:
while st and st[-1] > 0 and st[-1] < abs(a):
st.pop()
if st and st[-1] == abs(a):
st.pop()
else:
if not st or st[-1] < 0:
st.append(a)
return st
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.07.22 Today's Challenge (0) | 2023.07.22 |
---|---|
2023.07.21 Today's Challenge (0) | 2023.07.21 |
2023.07.19 Today's Challenge (0) | 2023.07.19 |
2023.07.18 Today's Challenge (0) | 2023.07.18 |
2023.07.17 Today's Challenge (0) | 2023.07.17 |
Comments