//485最大连续1的个数
func findMaxConsecutiveOnes(nums []int) (maxCnt int) {
cnt := 0
if len(nums) < 1 {
return
}
for _, v := range nums {
if v == 1 {
cnt++
} else {
maxCnt = max(maxCnt, cnt)
cnt = 0
}
}
maxCnt = max(maxCnt, cnt)
return
}
func max(x, y int) int {
if y > x {
return y
}
return x
}
//566重塑矩阵
func matrixReshape(nums [][]int, r int, c int) [][]int {
result := make([][]int, r) //初始化二维数组
for i := range result {
result[i] = make([]int, c)
}
hang := len(nums)
lie := len(nums[0])
if hang*lie != r*c {
return nums
}
for i := 0; i < hang*lie; i++ {
result[i/c][i%c] = nums[i/hang][i%lie] //行列规律小技巧
}
fmt.Println(result)
return result
}