Created
March 13, 2016 22:36
-
-
Save jianminchen/41e6cbd30228e9ba7204 to your computer and use it in GitHub Desktop.
Make It Anagram - Sort two string first, and then, using two pointers - sliding forward
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.Linq; | |
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 */ | |
var str1 = Console.ReadLine().ToCharArray().OrderBy(e => e).ToArray(); | |
var str2 = Console.ReadLine().ToCharArray().OrderBy(e => e).ToArray(); | |
var deletionCount = 0; | |
int n = 0; | |
int m = 0; | |
while (true) | |
{ | |
if (n >= str1.Length || m >= str2.Length) | |
break; | |
if (str1[n] < str2[m]) | |
{ | |
deletionCount++; | |
n++; | |
} | |
else if (str1[n] > str2[m]) | |
{ | |
deletionCount++; | |
m++; | |
} | |
else | |
{ | |
m++; | |
n++; | |
} | |
} | |
deletionCount += str2.Length - m + str1.Length - n; | |
Console.WriteLine(deletionCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment