Leetcode Note: Go - Sign of the Product of an Array

Sign of the Product of an Array - LeetCode
https://leetcode.com/problems/sign-of-the-product-of-an-array/

  • Go 言語で取り組んだメモ

回答

Golang solution faster than 100% with quick explanation - Sign of the Product of an Array - LeetCode
https://leetcode.com/problems/sign-of-the-product-of-an-array/solutions/1159844/golang-solution-faster-than-100-with-quick-explanation/

func arraySign(nums []int) int {
    sign := 1

    for _, num := range nums {
        if num <= -1 {
            sign = - sign
        } else if num == 0 {
            return 0
        }
    }

    return sign
}