Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ee7fe1

Browse files
committed
Go solution for sign of the product of an array
1 parentad0f0a4 commit2ee7fe1

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+
funcarraySign(nums []int)int {
7+
neg:=0
8+
for_,n:=rangenums {
9+
ifn==0 {
10+
return0
11+
}elseifn<0 {
12+
neg++
13+
}
14+
}
15+
ifneg%2==0 {
16+
return1
17+
}else {
18+
return-1
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp