Sha256: 5671d297592ce6ee9244b8cdedfeee50a662b3930edf44eb11275633a247e9b0

Contents?: true

Size: 543 Bytes

Versions: 285

Compression:

Stored size: 543 Bytes

Contents

using System.Linq;

public static class BracketPush
{
    public static bool IsPaired(string input)
    {
        var brackets = new string(input.Where(c => "[]{}()".Contains(c)).ToArray());
        var previousLength = brackets.Length;

        while (brackets.Length > 0)
        {
            brackets = brackets.Replace("[]", "").Replace("{}", "").Replace("()", "");

            if (brackets.Length == previousLength)
                return false;

            previousLength = brackets.Length;
        }

        return true;
    }
}

Version data entries

285 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.97 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.96 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.95 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.94 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.93 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.92 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.91 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.90 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.89 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.88 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.87 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.87 tracks/csharp/exercises/bracket-push/BracketPush.cs
trackler-2.2.1.86 tracks/csharp/exercises/bracket-push/BracketPush.cs
trackler-2.2.1.86 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.85 tracks/csharp/exercises/bracket-push/BracketPush.cs
trackler-2.2.1.85 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.84 tracks/csharp/exercises/bracket-push/BracketPush.cs
trackler-2.2.1.84 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.83 tracks/csharp/exercises/bracket-push/BracketPush.cs