< Summary

Information
Class: LeetCode.Algorithms.IsomorphicStrings.IsomorphicStringsTwoDictionaries
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\IsomorphicStrings\IsomorphicStringsTwoDictionaries.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 61
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsIsomorphic(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\IsomorphicStrings\IsomorphicStringsTwoDictionaries.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.IsomorphicStrings;
 13
 14/// <inheritdoc />
 15public class IsomorphicStringsTwoDictionaries : IIsomorphicStrings
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="s"></param>
 22    /// <param name="t"></param>
 23    /// <returns></returns>
 24    public bool IsIsomorphic(string s, string t)
 425    {
 426        var sDictionary = new Dictionary<char, char>();
 427        var tDictionary = new Dictionary<char, char>();
 28
 3229        for (var i = 0; i < s.Length; i++)
 1430        {
 1431            var sChar = s[i];
 1432            var tChar = t[i];
 33
 1434            if (sDictionary.TryGetValue(sChar, out var mappedTChar))
 335            {
 336                if (mappedTChar != tChar)
 137                {
 138                    return false;
 39                }
 240            }
 41            else
 1142            {
 1143                sDictionary[sChar] = tChar;
 1144            }
 45
 1346            if (tDictionary.TryGetValue(tChar, out var mappedSChar))
 347            {
 348                if (mappedSChar != sChar)
 149                {
 150                    return false;
 51                }
 252            }
 53            else
 1054            {
 1055                tDictionary[tChar] = sChar;
 1056            }
 1257        }
 58
 259        return true;
 460    }
 61}