Skip to main content
Commonmark migration
Source Link

###Bug###

Bug

The first condition maxSoFar < array[i] is wrong and should be removed. Otherwise a sequence such as 5 -10 6 will not find 6 as the max sum.

###Complicated expression###

Complicated expression

The other condition:

        if (array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you can simplify to:

          if (maxEndingHere <= 0) {

###Bug###

The first condition maxSoFar < array[i] is wrong and should be removed. Otherwise a sequence such as 5 -10 6 will not find 6 as the max sum.

###Complicated expression###

The other condition:

        if (array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you can simplify to:

          if (maxEndingHere <= 0) {

Bug

The first condition maxSoFar < array[i] is wrong and should be removed. Otherwise a sequence such as 5 -10 6 will not find 6 as the max sum.

Complicated expression

The other condition:

        if (array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you can simplify to:

          if (maxEndingHere <= 0) {
added 44 characters in body
Source Link
JS1
  • 28.6k
  • 3
  • 41
  • 83

#Complicated expression####Bug###

Your program seems correctThe first condition maxSoFar < array[i] is wrong and well writtenshould be removed. I only have one thing to point out: Otherwise a sequence such as 5 -10 6 will not find 6 as the max sum.

###Complicated expression###

The secondother condition here:

        if(maxSoFar < array[i] && (array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you getcan simplify to:

          if (maxSoFar < array[i] && maxEndingHere <= 0) {

#Complicated expression#

Your program seems correct and well written. I only have one thing to point out:

The second condition here:

        if(maxSoFar < array[i] && array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you get:

          if (maxSoFar < array[i] && maxEndingHere <= 0) {

###Bug###

The first condition maxSoFar < array[i] is wrong and should be removed. Otherwise a sequence such as 5 -10 6 will not find 6 as the max sum.

###Complicated expression###

The other condition:

        if (array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you can simplify to:

          if (maxEndingHere <= 0) {
Source Link
JS1
  • 28.6k
  • 3
  • 41
  • 83

#Complicated expression#

Your program seems correct and well written. I only have one thing to point out:

The second condition here:

        if(maxSoFar < array[i] && array[i] >= maxEndingHere + array[i]) {

is overly complicated. If you subtract array[i] from both sides, you get:

          if (maxSoFar < array[i] && maxEndingHere <= 0) {