Created
March 13, 2016 21:43
-
-
Save jianminchen/5c6f6a70a1be4f71a98a to your computer and use it in GitHub Desktop.
Make it anagram - using Dictionary, Hashset - more generic approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
class Solution { | |
static void Main(String[] args) { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ | |
string A=Console.ReadLine(); | |
string B=Console.ReadLine(); | |
HashSet<char> hashSet=new HashSet<char>(); | |
foreach (char c in A){ | |
hashSet.Add(c); | |
} | |
foreach (char c in B){ | |
hashSet.Add(c); | |
} | |
Dictionary<char,int> dic1=new Dictionary<char,int>(); | |
Dictionary<char,int> dic2=new Dictionary<char,int>(); | |
foreach (char c in hashSet){ | |
dic1.Add(c,0); | |
dic2.Add(c,0); | |
} | |
foreach (char c in A){ | |
dic1[c]++; | |
} | |
foreach (char c in B){ | |
dic2[c]++; | |
} | |
int rez=0; | |
foreach (char c in hashSet){ | |
rez+=Math.Abs(dic1[c]-dic2[c]); | |
} | |
Console.WriteLine(rez); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment