How would I search a range of ranged values using C#

后端 未结 8 1561
攒了一身酷
攒了一身酷 2021-02-10 20:24

I have a list of values like this

1000, 20400
22200, 24444

The ranges don\'t overlap.

What I want to do is have a c# function that can

8条回答
  •  星月不相逢
    2021-02-10 20:52

    Assuming your ranges don't overlap:

    -> Put all your range numbers in an array.

    -> Sort your array.

    -> Also keep a HashSet for your startvalues.

    -> Now do a binary search on your number. Two possiblities:

    --> Array range left of (smaller then) your number is a start value: your number is in range.

    --> Array range left of (smaller then) your number is not a start value: your number is not in range.

提交回复
热议问题