题目:
思想:
一开始又读错题了,以为是将colsum
分成upper
和 lower
两个数组,
结果是将将colsum[i]
分成upper[i]
和 lower[i]
两个数。
并且upper[i]
和lower[i]
的和等于colsum[i]
。
在每一次的循环里,获取colsum
的值,然后判断0,1,2仨种情况,0直接不管,2的话平均分配。
1的话,直接给当前最小的那个数组。(这里我用的upper
和lower
本身的参数来记录剩余数字)。
在最开始的时候判断if sum(colsum) != upper + lower
, 最后判断if upper + lower != 0
。
At first, I misunderstood the question again, thinking that it was about dividing colsum
into two arrays, upper
and lower
. However, it turned out that it was about dividing colsum[i]
into two numbers, upper[i]
and lower[i]
. Additionally, the sum of upper[i]
and lower[i]
should be equal to colsum[i]
.
In each iteration, the value of colsum
is obtained, and then three scenarios, 0, 1, and 2, are considered. If it’s 0, it is ignored. If it’s 2, the values are evenly distributed. If it’s 1, it is assigned to the array with the current minimum value (using the remaining numbers in upper and lower than parameters).
At the beginning, it is checked whether if sum(colsum) != upper + lower
, and finally, it is checked whether if upper + lower != 0
.
代码:
1 | class Solution: |