c# - how to calculate the number of common integers between two sorted sets -


i need count number of integers between 2 sorted sets determine if lotto ticket winner. 1 sorted set being winningnumbers , other ticketnumbers. told there intersect function cannot find function achieve required results. ideally function returns int representing number of common integers between sets.

even if it's not sorted works:

ienumerable<int> winning = winningnumbers.intersect(ticketnumbers); int countofwinningnumbers = winning.count(); 

if want process further better create collection:

list<int> winninglist = winning.tolist(); int countofwinningnumbers = winninglist.count; 

since you've asked explicitly sortedset approach, using sortedset.intersectwith might more efficient(o(n)) modifies source set:

sortedset<int> winningnumbers = new sortedset<int> { 2, 3, 7 }; sortedset<int> ticketnumbers = new sortedset<int> { 1, 2, 3, 4, 5 };  ticketnumbers.intersectwith(winningnumbers);  // ticketnumbers contains 2 , 3 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -