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

add check_permutation.rs #711

Closed

Conversation

mengfansheng-git
Copy link
Contributor

@mengfansheng-git mengfansheng-git commented May 6, 2024

Given two strings s1 and s2.
Determine whether the characters of one of the strings can be rearranged to become another string.

@codecov-commenter
Copy link

codecov-commenter commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.79%. Comparing base (260b448) to head (ac3338c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #711   +/-   ##
=======================================
  Coverage   94.78%   94.79%           
=======================================
  Files         298      299    +1     
  Lines       22161    22188   +27     
=======================================
+ Hits        21006    21033   +27     
  Misses       1155     1155           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -0,0 +1,40 @@
//! Given two strings s1 and s2 consisting of lowercase letters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if they are not lowercase letters?

Comment on lines 10 to 11
s1.chars()
.all(|c| s1.matches(c).count() == s2.matches(c).count())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the time complexity of this? $O(n^2)$? I think one can do it in a linear time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the help of a hash table to record the number of occurrences of a character and then compare the time complexity should be linear time.

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.

None yet

4 participants