Skip to content

Commit 2ee7fe1

Browse files
committed
Go solution for sign of the product of an array
1 parent ad0f0a4 commit 2ee7fe1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Time: O(n)
3+
Space: O(1)
4+
*/
5+
6+
func arraySign(nums []int) int {
7+
neg := 0
8+
for _, n := range nums {
9+
if n == 0 {
10+
return 0
11+
} else if n < 0 {
12+
neg++
13+
}
14+
}
15+
if neg%2 == 0 {
16+
return 1
17+
} else {
18+
return -1
19+
}
20+
}

0 commit comments

Comments
 (0)