Skip to content

Instantly share code, notes, and snippets.

@broqdev
Created October 14, 2014 04:04
Show Gist options
  • Select an option

  • Save broqdev/69be1f7be7d869e3ac6c to your computer and use it in GitHub Desktop.

Select an option

Save broqdev/69be1f7be7d869e3ac6c to your computer and use it in GitHub Desktop.

Revisions

  1. broqdev created this gist Oct 14, 2014.
    10 changes: 10 additions & 0 deletions circlemax_linear
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    当前是i,j in [0...i),first pass算max(A[i]+A[j]+i-j),second pass 算max(A[i]+A[j]+n-(i-j))

    第一次用公式max_value = max(max_value+1, A[i-1]+1)

    第二次用公式max_value = max(max_value-1, A[i-1]+n-1)

    for i in xrange(len(ar)):
    #try to update max_value
    ret = max(ret, A[i]+max_value)
    这个循环写两次,用两个不同的公式