Skip to content

Instantly share code, notes, and snippets.

@mstrzele
Last active June 26, 2022 19:52
Show Gist options
  • Save mstrzele/cdee50bff9a7031accd4919c8706602d to your computer and use it in GitHub Desktop.
Save mstrzele/cdee50bff9a7031accd4919c8706602d to your computer and use it in GitHub Desktop.
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