Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 22:05
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/fbf8e9049d3a1539ee87 to your computer and use it in GitHub Desktop.
Save jianminchen/fbf8e9049d3a1539ee87 to your computer and use it in GitHub Desktop.
MakeItAnagram - using one array, first string each char - add to the array, second string each char - take away from the array, sum of abs value of each item.
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args)
{
string A = Console.ReadLine();
string B = Console.ReadLine();
int[] a = new int[123];
int length = A.Length;
for (int i = 0; i < length; i++)
{
a[A[i]]++;
}
length = B.Length;
for (int i = 0; i < length; i++)
{
a[B[i]]--;
}
int count = 0;
for (int i = 0; i < 123; i++)
{
int k = a[i];
if (k != 0)
{
count += k < 0 ? -k : k;
}
}
Console.WriteLine(count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment