mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 01:15:57 +08:00
Update 0048、1011
This commit is contained in:
@ -10,8 +10,9 @@ Rotate the image by 90 degrees (clockwise).
|
|||||||
|
|
||||||
You have to rotate the image **[in-place](https://en.wikipedia.org/wiki/In-place_algorithm)**, which means you have to modify the input 2D matrix directly. **DO NOT** allocate another 2D matrix and do the rotation.
|
You have to rotate the image **[in-place](https://en.wikipedia.org/wiki/In-place_algorithm)**, which means you have to modify the input 2D matrix directly. **DO NOT** allocate another 2D matrix and do the rotation.
|
||||||
|
|
||||||
**Example 1:**
|
**Example 1**:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Given input matrix =
|
Given input matrix =
|
||||||
[
|
[
|
||||||
@ -28,8 +29,9 @@ You have to rotate the image **[in-place](https://en.wikipedia.org/wiki/In-plac
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
**Example 2:**
|
**Example 2**:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Given input matrix =
|
Given input matrix =
|
||||||
[
|
[
|
||||||
|
@ -12,6 +12,7 @@ You have to rotate the image **[in-place](https://en.wikipedia.org/wiki/In-plac
|
|||||||
|
|
||||||
**Example 1**:
|
**Example 1**:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Given input matrix =
|
Given input matrix =
|
||||||
[
|
[
|
||||||
@ -30,6 +31,7 @@ You have to rotate the image **[in-place](https://en.wikipedia.org/wiki/In-plac
|
|||||||
|
|
||||||
**Example 2**:
|
**Example 2**:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Given input matrix =
|
Given input matrix =
|
||||||
[
|
[
|
||||||
|
@ -73,8 +73,6 @@ Return the least weight capacity of the ship that will result in all the package
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
||||||
package leetcode
|
|
||||||
|
|
||||||
func shipWithinDays(weights []int, D int) int {
|
func shipWithinDays(weights []int, D int) int {
|
||||||
maxNum, sum := 0, 0
|
maxNum, sum := 0, 0
|
||||||
for _, num := range weights {
|
for _, num := range weights {
|
||||||
@ -98,6 +96,22 @@ func shipWithinDays(weights []int, D int) int {
|
|||||||
return low
|
return low
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calSum(mid, m int, nums []int) bool {
|
||||||
|
sum, count := 0, 0
|
||||||
|
for _, v := range nums {
|
||||||
|
sum += v
|
||||||
|
if sum > mid {
|
||||||
|
sum = v
|
||||||
|
count++
|
||||||
|
// 分成 m 块,只需要插桩 m -1 个
|
||||||
|
if count > m-1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user