diff --git a/lib/max_subarray.py b/lib/max_subarray.py index 4e892e0..d8e0afb 100644 --- a/lib/max_subarray.py +++ b/lib/max_subarray.py @@ -9,4 +9,12 @@ def max_sub_array(nums): return 0 if len(nums) == 0: return 0 - pass + + now_max = 0 + max_ending_here = nums[0] + + for i in range(len(nums)): + now_max = max(nums[i], now_max + nums[i]) + max_ending_here = max(max_ending_here, now_max) + return max_ending_here + diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 70a3353..1bca2d5 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -7,4 +7,13 @@ def newman_conway(num): Time Complexity: ? Space Complexity: ? """ - pass + if num == 0: + raise ValueError + + if num == 1: + return '1' + + sequence = [0, 1, 1] + for i in range(3, num + 1): + sequence.append (sequence[sequence[i - 1]] + sequence[i - sequence[i -1]]) + return ' '.join([str(s) for s in sequence[1:]])