Code Monkey home page Code Monkey logo

Comments (4)

halfrost avatar halfrost commented on June 12, 2024

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.

from leetcode-go.

MetalworkColossus avatar MetalworkColossus commented on June 12, 2024

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"

from leetcode-go.

halfrost avatar halfrost commented on June 12, 2024

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.

from leetcode-go.

MetalworkColossus avatar MetalworkColossus commented on June 12, 2024

@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.

from leetcode-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.