Skip to content

fix(Go): wrong pass of check parameters #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions solution/0400-0499/0410.Split Array Largest Sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ public:
### **Go**

```go
func splitArray(nums []int, m int) int {
func splitArray(nums []int, k int) int {
mx := -1
for _, num := range nums {
mx = max(mx, num)
}
left, right := mx, int(1e9)
for left < right {
mid := (left + right) >> 1
if check(nums, m, mid) {
if check(nums, k, mid) {
right = mid
} else {
left = mid + 1
Expand All @@ -173,7 +173,7 @@ func splitArray(nums []int, m int) int {
return left
}

func check(nums []int, m, x int) bool {
func check(nums []int, k, x int) bool {
s, cnt := 0, 1
for _, num := range nums {
if s+num > x {
Expand All @@ -183,7 +183,7 @@ func check(nums []int, m, x int) bool {
s += num
}
}
return cnt <= m
return cnt <= k
}

func max(a, b int) int {
Expand Down
8 changes: 4 additions & 4 deletions solution/0400-0499/0410.Split Array Largest Sum/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ public:
### **Go**

```go
func splitArray(nums []int, m int) int {
func splitArray(nums []int, k int) int {
mx := -1
for _, num := range nums {
mx = max(mx, num)
}
left, right := mx, int(1e9)
for left < right {
mid := (left + right) >> 1
if check(nums, m, mid) {
if check(nums, k, mid) {
right = mid
} else {
left = mid + 1
Expand All @@ -157,7 +157,7 @@ func splitArray(nums []int, m int) int {
return left
}

func check(nums []int, m, x int) bool {
func check(nums []int, k, x int) bool {
s, cnt := 0, 1
for _, num := range nums {
if s+num > x {
Expand All @@ -167,7 +167,7 @@ func check(nums []int, m, x int) bool {
s += num
}
}
return cnt <= m
return cnt <= k
}

func max(a, b int) int {
Expand Down
10 changes: 5 additions & 5 deletions solution/0400-0499/0410.Split Array Largest Sum/Solution.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
func splitArray(nums []int, m int) int {
func splitArray(nums []int, k int) int {
mx := -1
for _, num := range nums {
mx = max(mx, num)
}
left, right := mx, int(1e9)
for left < right {
mid := (left + right) >> 1
if check(nums, m, mid) {
if check(nums, k, mid) {
right = mid
} else {
left = mid + 1
Expand All @@ -15,7 +15,7 @@ func splitArray(nums []int, m int) int {
return left
}

func check(nums []int, m, x int) bool {
func check(nums []int, k, x int) bool {
s, cnt := 0, 1
for _, num := range nums {
if s+num > x {
Expand All @@ -25,12 +25,12 @@ func check(nums []int, m, x int) bool {
s += num
}
}
return cnt <= m
return cnt <= k
}

func max(a, b int) int {
if a > b {
return a
}
return b
}
}