-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dynamic-programming #32
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"python.testing.unittestArgs": [ | ||
"-v", | ||
"-s", | ||
"./tests", | ||
"-p", | ||
"*test.py" | ||
], | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"cSpell.words": [ | ||
"curr" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,31 @@ def max_sub_array(nums): | |
Returns 0 if nums is None or an empty list. | ||
Time Complexity: ? | ||
Space Complexity: ? | ||
Does this have to be contiguous? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
""" | ||
if nums == None: | ||
return 0 | ||
if len(nums) == 0: | ||
return 0 | ||
pass | ||
# # Arrange | ||
# input = [50, 3, -50, 50, 3] | ||
# output = 56 | ||
# input1 = [-2, -1] | ||
# output = [-1] | ||
|
||
max_so_far = 0 | ||
max_ending = 0 | ||
|
||
for i in nums: | ||
max_ending += i | ||
|
||
if max_ending > max_so_far: | ||
max_so_far = max_ending | ||
|
||
# when max sum is less than 0/negative num | ||
if max_so_far <= 0: | ||
return max(nums) | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note putting this |
||
return max_so_far | ||
|
||
# Run Time: 0(n) | ||
# Space: O(1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,21 @@ | |
# Space Complexity: ? | ||
def newman_conway(num): | ||
""" Returns a list of the Newman Conway numbers for the given value. | ||
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: o(n) | ||
Space Complexity: 0(n) | ||
""" | ||
Comment on lines
5
to
9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Well done |
||
pass | ||
# count of num and the num itself | ||
# input = 13 | ||
# output = 1113 -> 3113 -> 132113-> 1113122113 -> 311311222113 -> 13211321322113 -> | ||
if num == 0: | ||
raise ValueError | ||
if num == 1: | ||
return "1" | ||
|
||
sequence = [0, 1, 1] | ||
for val in range(3, num+1): | ||
nc = sequence[sequence[val - 1]] + sequence[val - sequence[val - 1]] | ||
sequence.append(nc) | ||
|
||
return ' '.join([str(s) for s in sequence[1:]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably add
.vscode
to your.gitignore
file.