Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 21:39
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/050b64f483c9a251d472 to your computer and use it in GitHub Desktop.
Save jianminchen/050b64f483c9a251d472 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MakeItAnagram
{
class Program
{
static void Main(string[] args)
{
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
Console.WriteLine(getNumberOfDeletion(s1, s2));
}
/*
* Length of string s1, s2, from >=1, <=10000
* lowercase latin letter a - z
*/
public static int getNumberOfDeletion(string s1, string s2)
{
int SIZE = 26;
int count = 0;
int[] sumA = getSumArray(s1);
int[] sumB = getSumArray(s2);
for(int i=0; i< SIZE; i++)
{
count += Math.Abs(sumA[i] - sumB[i]);
}
return count;
}
public static int[] getSumArray(string s1)
{
int SIZE = 26;
int[] sumA = new int[SIZE];
foreach (char c in s1)
{
sumA[c - 'a']++;
}
return sumA;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment