Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 22:24
Show Gist options
  • Save jianminchen/fc8b4309efe00d67a640 to your computer and use it in GitHub Desktop.
Save jianminchen/fc8b4309efe00d67a640 to your computer and use it in GitHub Desktop.
Make It Anagram - C# IList, distince method and functional programming
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Solution1
{
class Solution
{
static void Main(string[] args)
{
IList<char> s1 = new List<char>();
IList<char> s2 = new List<char>();
string str1 = Console.ReadLine();
string str2 = Console.ReadLine();
for (int i = 0; i < str1.Length; i++)
{
char a = str1.ElementAt(i);
s1.Add(a);
}
for (int i = 0; i < str2.Length; i++)
{
char a = str2.ElementAt(i);
s2.Add(a);
}
var d1 = s1.Distinct();
var d2 = s2.Distinct();
int count=0;
foreach (var v in d1)
{
int a = count + s1.Count(c => c == v);
int b = count + s2.Count(c => c == v);
if (a > b)
{
count += a - b;
}
else
{
count += b - a;
}
}
var e = s2.Except(s1);
foreach (var v in e)
{
count = count + s2.Count(c => c == v);
}
Console.WriteLine(count);
//string z=Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment