Quick actions

cmd+k|ctrl+k

Navigation

Languages

Remove Outermost Parentheses C#

Snippet info

Language

Csharp

Visibility

public

Author

syed205

Created

2019-06-12T13:08:13Z

Updated

2019-06-12T13:08:13Z

using System;

class MainClass {
    static void Main() {
        string paren = "(()())(())(()(()))";
        var parenList = paren.ToCharArray();
        int counter = 0;
        for(int i=0;i<parenList.Length;i++){
            if(parenList[i] == '('){
                counter++;
                if(counter > 1){
                    Console.Write('(');
                }
            }else{
                counter--;
                if(counter != 0){
                    Console.Write(')');
                }
            }
        }
    }
}
INFO