본문 바로가기
python-algorithm

Leetcode 1822. Sign of the Product of an Array

by 무적김두칠 2021. 8. 19.

1
2
3
4
5
6
7
8
pythonclass Solution:
    def arraySign(self, nums: List[int]) -> int:
        cnt=1
        for i in nums:
            cnt*=i
        if cnt>0 : return 1
        elif cnt ==0 : return 0
        else : return -1
cs

문제 자체가 크게 어렵지 않아요
입력받은 리스트의 하나하나 곱한것의 부호 에 따라서 리턴해주면 되는 문제입니다.

반응형

댓글