Created
March 13, 2016 22:05
-
-
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.
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) | |
{ | |
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