Algorithm to find the maximum subsequence of an array of positive numbers . Catch : No adjacent elements allowed

前端 未结 13 1122
甜味超标
甜味超标 2020-12-24 04:42

For example, given

A = [1,51,3,1,100,199,3], maxSum = 51 + 1 + 199 = 251.

clearly max(oddIndexSum,evenIndexSum) does not

相关标签:
13条回答
  • 2020-12-24 05:13

    max(oddIndexSum,evenIndexSum) does not work

    For the example you gave, it does - however, if you have something like: A = [1, 51, 3, 2, 41, 23, 20], you can have 51 + 2 + 23 = 76, or you can have 51 + 41 + 20 = 112, which is clearly larger, and avoids adjacent elements as well. Is this what you're looking for?

    0 讨论(0)
提交回复
热议问题