不是所有的,但有时所有【难度:1级】:
答案1:
using System.Collections.Generic;
using System.Linq;
public class Kata
{
public static string Remove(string str, Dictionary<char, int> what)
{
var chars = str.ToList();
int removeCount = 0;
for (int i = 0; i < chars.Count(); i++)
{
if (what.TryGetValue(chars[i], out removeCount) && removeCount > 0)
{
what.Remove(chars[i]);
what.Add(chars[i], --removeCount);
chars.RemoveAt(i);
i--;
}
}
return new string(chars.ToArray());
}
}
答案2:
using System.Collections.Generic;
using System.Linq;
public class Kata
{
public static string Remove(string str, Dictionary<char,int> what)
{
return string.Concat(str.Where(ch => !what.ContainsKey(ch) || what[ch]-- < 1).ToArray());
}
}
答案3:
using System.Collections.<