Created
July 19, 2012 21:04
-
-
Save PJensen/3146812 to your computer and use it in GitHub Desktop.
IsSubset
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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
| // more succinctly | |
| static bool IsSubset(int[] a, int[] b) | |
| { | |
| return !b.Except(a).Any(); | |
| } |
Author
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
bool isSubset = !b1.Except(a1).Any();