Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 21:56
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/a2258616e596c0328660 to your computer and use it in GitHub Desktop.
Save jianminchen/a2258616e596c0328660 to your computer and use it in GitHub Desktop.
Make It Anagram - using C# List class, remove method - remove common char set, and then, left are ones to be deleted.
using System;
using System.Collections.Generic;
namespace Solution
{
static class Solution
{
static void Main()
{
string word1 = Console.ReadLine();
if (word1 == null) return;
string word2 = Console.ReadLine();
if (word2 == null) return;
List<char> chars1 = new List<char>(word1.ToCharArray());
List<char> chars2 = new List<char>(word2.ToCharArray());
for (int i = chars1.Count - 1; i >= 0; i--)
{
if (chars2.Remove(chars1[i]))
{
chars1.RemoveAt(i);
}
}
for (int i = chars2.Count - 1; i >= 0; i--)
{
if (chars1.Remove(chars2[i]))
{
chars2.RemoveAt(i);
}
}
Console.WriteLine(chars1.Count + chars2.Count);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment