Skip to content

Instantly share code, notes, and snippets.

@PJensen
Created July 19, 2012 21:04
Show Gist options
  • Select an option

  • Save PJensen/3146812 to your computer and use it in GitHub Desktop.

Select an option

Save PJensen/3146812 to your computer and use it in GitHub Desktop.
IsSubset
static bool IsSubset(int[] a, int[] b)
{
var a1 = new List<int>(a);
var b1 = new List<int>(b);
foreach (var k in a1)
{
b1.Remove(k);
}
return b1.Count == 0;
}
// more succinctly
static bool IsSubset(int[] a, int[] b)
{
return !b.Except(a).Any();
}
@Templier
Copy link

bool isSubset = !b1.Except(a1).Any();

@PJensen
Copy link
Author

PJensen commented Jul 20, 2012

that's far superior -- working through a post where Big-O needs to be clear and obvious. Of course, I should expand Remove too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment