Find elements in a list that, together add up to a target number

前端 未结 4 612
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 11:03

Suppose I have a list:

List _arr = new List {1, 3, 4};

And a target of 4

I want to return

4条回答
  •  鱼传尺愫
    2021-01-07 11:16

    I don't think you can do that using a simple LINQ query. In fact, I'm having a hard time coming up with a simple solution for this using full-blown T-SQL!

    The problem is you're trying to return not single items, but various collections of items based on possible permutations.

    On that note, I do hope someone comes up with such a LINQ query, cos something tells me it would will be awesome. ;)

提交回复
热议问题