Created
March 13, 2016 21:39
-
-
Save jianminchen/050b64f483c9a251d472 to your computer and use it in GitHub Desktop.
HackerRank - String algorithm - Make it anagram - https://www.hackerrank.com/challenges/make-it-anagram/submissions/code/18344694
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.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