Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

akinyolci
Copy link

check each char and replace spaces with %20 Time Complexity = o(n)

check each char and replace  spaces with %20  Time Complexity = o(n)
Copy link
Collaborator

@brycedrennan brycedrennan left a 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) """
Copy link
Collaborator

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):
Copy link
Collaborator

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):
Copy link
Collaborator

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

@brycedrennan
Copy link
Collaborator

If we fixed this to be O(n) instead of O(n^2) it would look very similar to existing solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants