-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Update p03_urlify.py #256
Update p03_urlify.py #256
Conversation
check each char and replace spaces with %20 Time Complexity = o(n)
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.
Thank you for this contribution. There are a few suggestions I have.
@@ -21,6 +21,21 @@ def urlify_algo(string, length): | |||
return "".join(char_list[new_index:]) | |||
|
|||
|
|||
|
|||
def url_Ify(str1,length): | |||
""" check each char and replace spaces with %20 Time Complexity = o(n) """ |
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.
Appending to strings in python creates a new string every time. So complexity might actually be n^2
""" check each char and replace spaces with %20 Time Complexity = o(n) """ | ||
|
||
new = '' #create a emtpy string | ||
for i in range(length): |
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.
could just be
for c in str1
@@ -21,6 +21,21 @@ def urlify_algo(string, length): | |||
return "".join(char_list[new_index:]) | |||
|
|||
|
|||
|
|||
def url_Ify(str1,length): |
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.
generally should not have numbers in variable names
If we fixed this to be O(n) instead of O(n^2) it would look very similar to existing solution. |
check each char and replace spaces with %20 Time Complexity = o(n)