添加Go语言题解

This commit is contained in:
zouxinyao
2021-07-28 02:26:32 +08:00
parent 7eb8b4a9fd
commit 575b7612f0
52 changed files with 1679 additions and 104 deletions

View File

@@ -107,3 +107,23 @@ public:
}
};
```
Go Code:
```go
func pivotIndex(nums []int) int {
presum := 0
for _, num := range nums {
presum += num
}
var leftsum int
for i, num := range nums {
// 比较左半和右半是否相同
if presum - leftsum - num == leftsum {
return i
}
leftsum += num
}
return -1
}
```