< Summary

Information
Class: LeetCode.Algorithms.CheckIfTwoStringArraysAreEquivalent.CheckIfTwoStringArraysAreEquivalentIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfTwoStringArraysAreEquivalent\CheckIfTwoStringArraysAreEquivalentIterative.cs
Line coverage
93%
Covered lines: 27
Uncovered lines: 2
Coverable lines: 29
Total lines: 64
Line coverage: 93.1%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ArrayStringsAreEqual(...)90%101093.1%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfTwoStringArraysAreEquivalent\CheckIfTwoStringArraysAreEquivalentIterative.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.CheckIfTwoStringArraysAreEquivalent;
 13
 14/// <inheritdoc />
 15public class CheckIfTwoStringArraysAreEquivalentIterative : ICheckIfTwoStringArraysAreEquivalent
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n + m)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="word1"></param>
 22    /// <param name="word2"></param>
 23    /// <returns></returns>
 24    public bool ArrayStringsAreEqual(string[] word1, string[] word2)
 725    {
 2226        var word1CharsLength = word1.Select(w => w.Length).Sum();
 2127        var word2CharsLength = word2.Select(w => w.Length).Sum();
 28
 729        if (word1CharsLength != word2CharsLength)
 030        {
 031            return false;
 32        }
 33
 2834        int wordIndex1 = 0, wordIndex2 = 0, charIndex1 = 0, charIndex2 = 0;
 35
 9036        for (var i = 0; i < word1CharsLength; i++)
 4137        {
 4138            if (charIndex1 > word1[wordIndex1].Length - 1)
 839            {
 840                wordIndex1++;
 841                charIndex1 = 0;
 842            }
 43
 4144            if (charIndex2 > word2[wordIndex2].Length - 1)
 645            {
 646                wordIndex2++;
 647                charIndex2 = 0;
 648            }
 49
 4150            var c1 = word1[wordIndex1][charIndex1];
 4151            var c2 = word2[wordIndex2][charIndex2];
 52
 4153            if (c1 != c2)
 354            {
 355                return false;
 56            }
 57
 3858            charIndex1++;
 3859            charIndex2++;
 3860        }
 61
 462        return true;
 763    }
 64}