< Summary

Information
Class: LeetCode.Algorithms.MergeSortedArray.MergeSortedArrayThreePointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MergeSortedArray\MergeSortedArrayThreePointers.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Merge(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MergeSortedArray\MergeSortedArrayThreePointers.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.MergeSortedArray;
 13
 14/// <inheritdoc />
 15public class MergeSortedArrayThreePointers : IMergeSortedArray
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m + n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="nums1"></param>
 22    /// <param name="m"></param>
 23    /// <param name="nums2"></param>
 24    /// <param name="n"></param>
 25    public void Merge(int[] nums1, int m, int[] nums2, int n)
 426    {
 427        var nums1Index = m - 1;
 428        var nums2Index = n - 1;
 429        var k = m + n - 1;
 30
 831        while (nums1Index >= 0 && nums2Index >= 0)
 432        {
 433            if (nums1[nums1Index] > nums2[nums2Index])
 134            {
 135                nums1[k] = nums1[nums1Index];
 136                nums1Index--;
 137            }
 38            else
 339            {
 340                nums1[k] = nums2[nums2Index];
 341                nums2Index--;
 342            }
 43
 444            k--;
 445        }
 46
 1047        while (nums2Index >= 0)
 648        {
 649            nums1[k] = nums2[nums2Index];
 650            nums2Index--;
 651            k--;
 652        }
 453    }
 54}