By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

String Intersection

P: 1
Implement a function strIntersection(str1, str2) that takes two strings as input, and returns the intersection of the two, with each letter represented at most once. The letters should be in the order they appear in the first string.

eg. strIntersection("On hot sunny days", "There is much rain") => "n hsua"
Mar 16 '08 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Implement a function strIntersection(str1, str2) that takes two strings as input, and returns the intersection of the two, with each letter represented at most once. The letters should be in the order they appear in the first string.

eg. strIntersection("On hot sunny days", "There is much rain") => "n hsua"
Create an empty list. Let's call it intlist. Iterate on the first string. If the letter is in the second string but not in intlist, append it to intlist. Return a string with intlist as the argument to ''.join().
Mar 16 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.