< Summary

Information
Class: LeetCode.Algorithms.CheckIfStringsCanBeMadeEqualWithOperations2.CheckIfStringsCanBeMadeEqualWithOperations2BruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfStringsCanBeMadeEqualWithOperations2\CheckIfStringsCanBeMadeEqualWithOperations2BruteForce.cs
Line coverage
92%
Covered lines: 24
Uncovered lines: 2
Coverable lines: 26
Total lines: 68
Line coverage: 92.3%
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
CheckStrings(...)91.66%121292.3%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfStringsCanBeMadeEqualWithOperations2\CheckIfStringsCanBeMadeEqualWithOperations2BruteForce.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.CheckIfStringsCanBeMadeEqualWithOperations2;
 13
 14/// <inheritdoc />
 15public sealed class CheckIfStringsCanBeMadeEqualWithOperations2BruteForce : ICheckIfStringsCanBeMadeEqualWithOperations2
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^2)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="s1"></param>
 22    /// <param name="s2"></param>
 23    /// <returns></returns>
 24    public bool CheckStrings(string s1, string s2)
 2025    {
 2026        var n = s1.Length;
 27
 2028        var s1CharArray = s1.ToCharArray();
 29
 21230        for (var i = 0; i < n; i++)
 9331        {
 9332            if (s1CharArray[i] == s2[i])
 6733            {
 6734                continue;
 35            }
 36
 2637            var found = false;
 38
 5839            for (var j = i + 2; j < n; j += 2)
 2240            {
 2241                if ((j - i) % 2 != 0)
 042                {
 043                    continue;
 44                }
 45
 2246                if (s1CharArray[j] != s2[i])
 347                {
 348                    continue;
 49                }
 50
 1951                (s1CharArray[j], s1CharArray[i]) = (s1CharArray[i], s1CharArray[j]);
 52
 1953                found = true;
 54
 1955                break;
 56            }
 57
 2658            if (found)
 1959            {
 1960                continue;
 61            }
 62
 763            return false;
 64        }
 65
 1366        return true;
 2067    }
 68}