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 p02_check_permutation.py #248

Closed
wants to merge 1 commit into from
Closed

Conversation

Cesarsk
Copy link
Contributor

@Cesarsk Cesarsk commented Aug 16, 2022

Isn't it enough to simply check Counter(str1) == Counter(str2) instead of checking the length? Looks superflous to me. I may be wrong tho.

Isn't it enough to simply check Counter(str1) == Counter(str2) instead of checking the length? Looks superflous to me. I may be wrong tho.
@brycedrennan
Copy link
Collaborator

It's a short-circuit using a "cheap" calculation. Length checks are O(1) but if the strings are very long (megabytes) then running Counter is relatively expensive.

Cesarsk added a commit to Cesarsk/CtCI-6th-Edition-Python that referenced this pull request Aug 17, 2022
added a comment to one of the functions according to careercup#248
brycedrennan pushed a commit that referenced this pull request Aug 25, 2022
added a comment to one of the functions according to #248
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