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.180 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.179 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.178 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.177 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.176 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.175 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.174 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.173 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.172 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.171 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.170 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.169 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.167 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.166 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.165 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.164 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.163 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.162 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.161 tracks/csharp/exercises/bracket-push/Example.cs
trackler-2.2.1.160 tracks/csharp/exercises/bracket-push/Example.cs