![]() |
VOOZH | about |
Given two strings, the task is to count the number of characters that appear in both strings, ignoring case and duplicates if needed.
Example:
Input:
s1 = "apple"
s2 = "grape"Output: 3
Below are the several methods to perform this task:
This method converts both strings into sets and finds common characters using the intersection.
3
Explanation:
This method iterates through one string and checks if each unique character exists in the other string.
3
Explanation:
This method manually iterates through each character of one string and counts matches in the other string.
3
Explanation: