Last active
June 26, 2022 19:52
-
-
Save mstrzele/cdee50bff9a7031accd4919c8706602d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package solution | |
// you can also use imports, for example: | |
// import "fmt" | |
// import "os" | |
// you can write to stdout for debugging purposes, e.g. | |
// fmt.Println("this is a debug message") | |
func Solution(A []int) int { | |
N := len(A) | |
if N == 0 { | |
return -1 | |
} | |
var sum int64 = 0 | |
for P := 0; P < N; P++ { | |
sum += int64(A[P]) | |
} | |
var sumLeft, sumRight int64 = 0, 0 | |
for P := 0; P < N; P++ { | |
sumRight = sum - sumLeft - int64(A[P]) | |
if sumLeft == sumRight { | |
return P | |
} | |
sumLeft += int64(A[P]) | |
} | |
return -1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment