1.suscription

No11.week11 maxSubArray


2.How to Slove

     Hint:
          consider contiguous subsequences ending exactly at position j.

     Solve:
          记f(j) = 以aj为结尾的最大和。
          f(0) = 0
          f(1) = a1
          f(2) = max{ f(1) , f(1) + a2}
          ...
          f(j) = max{ aj, f(j - 1)+ aj} // optimal substructure

     算法复杂度:
          时间复杂度:分别以每个数字为结尾,一共n个数字,故n个循环。每个循环做一个比较,f(j - 1), f(j - 1)+ aj两个谁比较大,复杂度为1,因此算法的时间复杂度为O(n)。
No11.week11 maxSubArray

相关文章:

  • 2021-12-16
  • 2022-12-23
  • 2021-08-05
  • 2021-08-27
  • 2021-05-28
  • 2021-07-20
  • 2021-12-12
  • 2021-07-30
猜你喜欢
  • 2021-07-21
  • 2021-10-06
  • 2021-11-22
  • 2022-02-28
  • 2021-08-31
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案