Dota2 Senate


  • 0

    Click here to see the full article post


  • 0
    J

    we could use a stack and a temp list of char, which is much easier to read.

            public string PredictPartyVictory( string senate )
    	{
    		var stack = new Stack<char>();
    		var vSenators = senate.ToList();
    		while ( vSenators.Count > 0 )
    		{
    			List<char> vLefts = new List<char>();
    			foreach ( var c in vSenators )
    			{
    				if ( stack.Count == 0 || stack.Peek() == c )
    				{
    					stack.Push( c );
    				}
    				else
    				{
    					vLefts.Add( stack.Pop() );
    				}
    			}
    
    			vSenators = vLefts;
    		}
    		if ( stack.Peek() == 'R' )
    		{
    			return "Radiant";
    		}
    		else
    		{
    			return "Dire";
    		}
    	}

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.