< Summary

Information
Class: LeetCode.Algorithms.FindTargetIndicesAfterSortingArray.FindTargetIndicesAfterSortingArrayBinarySearch
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTargetIndicesAfterSortingArray\FindTargetIndicesAfterSortingArrayBinarySearch.cs
Line coverage
92%
Covered lines: 25
Uncovered lines: 2
Coverable lines: 27
Total lines: 61
Line coverage: 92.5%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TargetIndices(...)91.66%121292.59%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTargetIndicesAfterSortingArray\FindTargetIndicesAfterSortingArrayBinarySearch.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.FindTargetIndicesAfterSortingArray;
 13
 14/// <inheritdoc />
 15public class FindTargetIndicesAfterSortingArrayBinarySearch : IFindTargetIndicesAfterSortingArray
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(k)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <param name="target"></param>
 23    /// <returns></returns>
 24    public IList<int> TargetIndices(int[] nums, int target)
 325    {
 326        Array.Sort(nums);
 27
 328        var left = 0;
 329        var right = nums.Length - 1;
 30
 1031        while (left < right)
 732        {
 733            var mid = left + ((right - left) / 2);
 34
 735            if (nums[mid] >= target)
 336            {
 337                right = mid;
 338            }
 439            else if (nums[mid] < target)
 440            {
 441                left = mid + 1;
 442            }
 743        }
 44
 345        if (nums[left] != target)
 046        {
 047            return new List<int>();
 48        }
 49
 350        var result = new List<int>();
 51
 752        while (left < nums.Length && nums[left] == target)
 453        {
 454            result.Add(left);
 55
 456            left++;
 457        }
 58
 359        return result;
 360    }
 61}