-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1054 from 0xff-dev/1760
Add solution and test-cases for problem 1760
- Loading branch information
Showing
3 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
41 changes: 27 additions & 14 deletions
41
leetcode/1701-1800/1760.Minimum-Limit-of-Balls-in-a-Bag/README.md
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
34 changes: 32 additions & 2 deletions
34
leetcode/1701-1800/1760.Minimum-Limit-of-Balls-in-a-Bag/Solution.go
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int, maxOperations int) int { | ||
var can func(int) bool | ||
can = func(limit int) bool { | ||
op := maxOperations | ||
for _, n := range nums { | ||
if n <= limit { | ||
continue | ||
} | ||
// 9 /3 | ||
times := n / limit | ||
if n%limit == 0 { | ||
times-- | ||
} | ||
if times > op { | ||
return false | ||
} | ||
op -= times | ||
} | ||
return true | ||
} | ||
left, right := 1, 1000000001 | ||
ans := -1 | ||
for left < right { | ||
mid := (left + right) / 2 | ||
if can(mid) { | ||
right = mid | ||
ans = mid | ||
continue | ||
} | ||
left = mid + 1 | ||
} | ||
return ans | ||
} |
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