Created
August 14, 2018 05:05
-
-
Save kailaix/f440ee5ca763d62033c815d718b199f6 to your computer and use it in GitHub Desktop.
find largest number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_largest(L): | |
| N = len(L) | |
| minL = [ [None] * N for j in range(N)] | |
| sumL = [ [None] * N for j in range(N)] | |
| def helper(i): | |
| if i==0: | |
| minL[0][0] = L[0] | |
| else: | |
| for j in range(i): | |
| minL[j][i] = min(minL[j][i-1], L[i]) | |
| minL[i][i] = L[i] | |
| if i+1<N: | |
| helper(i+1) | |
| helper(0) | |
| def helper2(i): | |
| if i==0: | |
| sumL[0][0] = L[0] | |
| else: | |
| for j in range(i): | |
| sumL[j][i] = sumL[j][i-1] + L[i] | |
| sumL[i][i] = L[i] | |
| if i+1<N: | |
| helper2(i+1) | |
| helper2(0) | |
| curM = 0 | |
| for i in range(N): | |
| for j in range(i,N): | |
| curM = max(curM, minL[i][j] * sumL[i][j]) | |
| return curM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment