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 QuestionA.java #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikecelletti
Copy link

@mikecelletti mikecelletti commented Jun 7, 2020

This change should greatly improve the best case runtime. The current version of the algorithm always sorts both strings before doing any checks. If the strings are not the same length, then they can't be permutations of one another. In cases where they are not the same length, this change will shorten the algorithm's time to O(1) as it only makes a comparison of the strings' length property before returning.

@mikecelletti
Copy link
Author

This check is implemented in the alternate answer, and should serve the same purpose here

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.

1 participant