728x90
난이도 : easy
arr에 있는 요소 중 2배인 원소가 있으면 true를 return
class Solution:
def checkIfExist(self, arr: List[int]) -> bool:
ans = []
for i in arr:
if i * 2 in ans or i / 2 in ans:
return True
ans.append(i)
return False
ans라는 리스트를 설정하고, ans 리스트 내에 2배나 1/2인 원소가 있으면 true를 return.
중복되지 않도록 일부러 if문 뒤에 append를 추가
Runtime : 3ms (42.22%)
Memory : 18.05MB (6.75%)
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Python] 1462. Course Schedule IV (0) | 2025.01.28 |
---|---|
[Python] 941. Valid Mountain Array (0) | 2025.01.27 |
[Python] 2425. Bitwise XOR of All Pairings (0) | 2025.01.25 |
[Python] 2429. Minimize XOR (0) | 2025.01.24 |
[Python] 802. Find Eventual Safe States (0) | 2025.01.24 |