Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/5c6f6a70a1be4f71a98a to your computer and use it in GitHub Desktop.
Save jianminchen/5c6f6a70a1be4f71a98a to your computer and use it in GitHub Desktop.
Make it anagram - using Dictionary, Hashset - more generic approach
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