< Summary

Information
Class: LeetCode.Algorithms.SentenceSimilarity3.SentenceSimilarity3TwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SentenceSimilarity3\SentenceSimilarity3TwoPointers.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 61
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
AreSentencesSimilar(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SentenceSimilarity3\SentenceSimilarity3TwoPointers.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.SentenceSimilarity3;
 13
 14/// <inheritdoc />
 15public class SentenceSimilarity3TwoPointers : ISentenceSimilarity3
 16{
 17    /// <summary>
 18    ///     Time complexity - O(min(n, m))
 19    ///     Space complexity - O(n + m)
 20    /// </summary>
 21    /// <param name="sentence1"></param>
 22    /// <param name="sentence2"></param>
 23    /// <returns></returns>
 24    public bool AreSentencesSimilar(string sentence1, string sentence2)
 1125    {
 1126        var sentence1Words = sentence1.Split(' ');
 1127        var sentence2Words = sentence2.Split(' ');
 28
 1129        var sentence1Left = 0;
 1130        var sentence1Right = sentence1Words.Length - 1;
 31
 1132        var sentence2Left = 0;
 1133        var sentence2Right = sentence2Words.Length - 1;
 34
 2535        while (sentence1Left <= sentence1Right && sentence2Left <= sentence2Right)
 2036        {
 2037            var word1Left = sentence1Words[sentence1Left];
 2038            var word1Right = sentence1Words[sentence1Right];
 39
 2040            var word2Left = sentence2Words[sentence2Left];
 2041            var word2Right = sentence2Words[sentence2Right];
 42
 2043            if (word1Left == word2Left)
 944            {
 945                sentence1Left++;
 946                sentence2Left++;
 947            }
 1148            else if (word1Right == word2Right)
 549            {
 550                sentence1Right--;
 551                sentence2Right--;
 552            }
 53            else
 654            {
 655                return false;
 56            }
 1457        }
 58
 559        return true;
 1160    }
 61}