sorted search increase performance

前端 未结 4 470
野性不改
野性不改 2021-01-29 14:53

Running through exercises on testdome...currently looking at https://www.testdome.com/for-developers/solve-question/9877

Implement function CountNum

4条回答
  •  花落未央
    2021-01-29 15:30

    This passed all 4 tests:

    public static int CountNumbers(int[] sortedArray, int lessThan)
    {
        int val = Array.BinarySearch(sortedArray, lessThan);
        return val < 0 ? ~val : val;
    }
    

    As others have said, they expect you to use Array.BinarySearch which I didn't realise until read the 2nd hint.

提交回复
热议问题