add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
21
solutions/7/q724/solution.go
Normal file
21
solutions/7/q724/solution.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package q724
|
||||
|
||||
func pivotIndex(nums []int) int {
|
||||
sumL, sumR := 0, 0
|
||||
for _, n := range nums {
|
||||
sumR += n
|
||||
}
|
||||
|
||||
for i := range nums {
|
||||
sumR -= nums[i]
|
||||
if i > 0 {
|
||||
sumL += nums[i-1]
|
||||
}
|
||||
if sumL == sumR {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
var _ = pivotIndex
|
||||
Loading…
Add table
Add a link
Reference in a new issue