lamiastella

max_area

Jun 2nd, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. class Solution:
  2.     # @param A : list of integers
  3.     # @return an integer
  4.     def largestRectangleArea(self, A):
  5.         max_sum = 0
  6.         if len(A) == 0:
  7.             return None
  8.         if len(A) == 1:
  9.             return A[0]
  10.         for i in range(len(A)):
  11.             count = 1
  12.             round_sum = 0
  13.             while i+count  <= len(A)-1:
  14.                 sum = min(A[i:i+count+1]) *  (count+1)
  15.                 count += 1
  16.                 if sum > round_sum:
  17.                     round_sum = sum
  18.                 if sum < round_sum:
  19.                     break
  20.                 if round_sum > max_sum:
  21.                     max_sum = round_sum
  22.         return max_sum
  23.  
  24.  
  25.  
  26. s = Solution()
  27. #list = [ 90, 58, 69, 70, 82, 100, 13, 57, 47, 18 ]
  28. list =  [ 65, 19, 8, 39, 14, 21, 83, 87, 95, 11, 14, 58, 11, 90,
  29.           34, 96, 34, 62, 96, 38, 58, 57, 12, 78, 57, 60, 7, 58,
  30.           56, 49, 36, 67, 69, 30, 74, 46, 97, 62, 47, 42, 43, 98,
  31.           60, 32, 39, 75, 69, 28, 35, 52, 89, 78, 4, 26, 65, 21,
  32.           39, 89, 87, 69, 48, 60, 6, 21, 5, 98, 52, 59 ]
  33.  
  34. #list = [51,33]
  35. #list = [ 6, 2, 5, 4, 5, 1, 6 ]
  36. #10
  37. print(s.largestRectangleArea(list))
  38.  
  39. Your function returned the following :
  40. 570
  41. The expected returned value :
  42. 700
Advertisement
Add Comment
Please, Sign In to add comment