Created
March 13, 2016 21:56
-
-
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.
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; | |
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