< Summary

Information
Class: LeetCode.Algorithms.TwoSum2InputArrayIsSorted.TwoSum2InputArrayIsSortedTwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoSum2InputArrayIsSorted\TwoSum2InputArrayIsSortedTwoPointers.cs
Line coverage
84%
Covered lines: 16
Uncovered lines: 3
Coverable lines: 19
Total lines: 50
Line coverage: 84.2%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TwoSum(...)83.33%6684.21%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoSum2InputArrayIsSorted\TwoSum2InputArrayIsSortedTwoPointers.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 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.TwoSum2InputArrayIsSorted;
 13
 14/// <inheritdoc />
 15public sealed class TwoSum2InputArrayIsSortedTwoPointers : ITwoSum2InputArrayIsSorted
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="numbers"></param>
 22    /// <param name="target"></param>
 23    /// <returns></returns>
 24    public int[] TwoSum(int[] numbers, int target)
 325    {
 326        var left = 0;
 327        var right = numbers.Length - 1;
 28
 529        while (left < right)
 530        {
 531            var sum = numbers[left] + numbers[right];
 32
 533            if (sum == target)
 334            {
 335                break;
 36            }
 37
 238            if (sum < target)
 039            {
 040                left++;
 041            }
 42            else
 243            {
 244                right--;
 245            }
 246        }
 47
 348        return [left + 1, right + 1];
 349    }
 50}