Closed MetalworkColossus closed 2 years ago
if sum+negativeMax <= 0 { return kad }
thx for the code sharing, but there is a small thing. ‘<=' is actually very confusing. It takes me a while to figure out that there is acutally no way for it to be less than 0. It makes more sense just checking whether they are equal only.
@MetalworkColossus sum+negativeMax can be less than 0. Thers are lots of negative number in the array, Suppose negativeMax is -2147483648, and sum is -2. In this condition, we must need to check whether their sum is negative or not.
if sum+negativeMax <= 0 { return kad }
thx for the code sharing, but there is a small thing. ‘<=' is actually very confusing. It takes me a while to figure out that there is acutally no way for it to be less than 0. It makes more sense just checking whether they are equal only.
@MetalworkColossus sum+negativeMax can be less than 0. Thers are lots of negative number in the array, Suppose negativeMax is -2147483648, and sum is -2. In this condition, we must need to check whether their sum is negative or not.
@halfrost There is no way negativeMax is -2147483648 when sum is-2. The negativeMax is the maximum sum subarray for the negative image of the original array. If original array's sum was -2, the negative array's sum would be 2, then negativeMax is at least 2 by defintion. The only thing needs to be checked is whether all the numbers in the array are negatives, which leads to "sum + negativeMax == 0"
if sum+negativeMax <= 0 { return kad }
thx for the code sharing, but there is a small thing. ‘<=' is actually very confusing. It takes me a while to figure out that there is acutally no way for it to be less than 0. It makes more sense just checking whether they are equal only.
@MetalworkColossus sum+negativeMax can be less than 0. Thers are lots of negative number in the array, Suppose negativeMax is -2147483648, and sum is -2. In this condition, we must need to check whether their sum is negative or not.
@halfrost There is no way negativeMax is -2147483648 when sum is-2. The negativeMax is the maximum sum subarray for the negative image of the original array. If original array's sum was -2, the negative array's sum would be 2, then negativeMax is at least 2 by defintion. The only thing needs to be checked is whether all the numbers in the array are negatives, which leads to "sum + negativeMax == 0"
@MetalworkColossus You seem to be right. I think there is a problem with my solution. I will rewrite the solution of this question when I am free. Thank you so much.
@MetalworkColossus You seem to be right. I think there is a problem with my solution. I will rewrite the solution of this question when I am free. Thank you so much.
Thank you. Your cookbook is very helpful. Glad to be of help.