Skip to main content
added 184 characters in body
Source Link
JaredPar
  • 759.3k
  • 152
  • 1.3k
  • 1.5k

Try this

static bool IsSubSet<A>(A[] set, A[] toCheck) { return set.Length == (toCheck.Intersect(set)).Count(); } 

The idea here is that Intersect will only return the values that are in both Arrays. At this point if the length of the resulting set is the same as the original set, then all elements in "set" are also in "check" and therefore "set" is a subset of "toCheck"

Note: My solution does not work if "set" has duplicates. I'm not changing it because I don't want to steal other people's votes.

Hint: I voted for Cameron's answer.

Try this

static bool IsSubSet<A>(A[] set, A[] toCheck) { return set.Length == (toCheck.Intersect(set)).Count(); } 

The idea here is that Intersect will only return the values that are in both Arrays. At this point if the length of the resulting set is the same as the original set, then all elements in "set" are also in "check" and therefore "set" is a subset of "toCheck"

Try this

static bool IsSubSet<A>(A[] set, A[] toCheck) { return set.Length == (toCheck.Intersect(set)).Count(); } 

The idea here is that Intersect will only return the values that are in both Arrays. At this point if the length of the resulting set is the same as the original set, then all elements in "set" are also in "check" and therefore "set" is a subset of "toCheck"

Note: My solution does not work if "set" has duplicates. I'm not changing it because I don't want to steal other people's votes.

Hint: I voted for Cameron's answer.

Source Link
JaredPar
  • 759.3k
  • 152
  • 1.3k
  • 1.5k

Try this

static bool IsSubSet<A>(A[] set, A[] toCheck) { return set.Length == (toCheck.Intersect(set)).Count(); } 

The idea here is that Intersect will only return the values that are in both Arrays. At this point if the length of the resulting set is the same as the original set, then all elements in "set" are also in "check" and therefore "set" is a subset of "toCheck"