C# why always compile error complain about List.Add


  • 0
    J

    I don`t even use list in my code. Build and Run well locally. But OJ keep complain below error.

    Compile Error:
    The best overloaded method match for `System.Collections.Generic.List<int>.Add(int)' has some invalid arguments

    public class Stack
    		{
    			private Queue<int> q = new Queue<int> ();
    
    			// Push element x onto stack.
    			public void Push (int x)
    			{
    				this.q.Enqueue (x);
    			}
    
    			// Removes the element on top of the stack.
    			public void Pop ()
    			{
    				if (this.q.Count > 0) {
    					var tmpQ = new Queue<int> ();
    					while (this.q.Count > 1)
    						tmpQ.Enqueue (this.q.Dequeue ());
    
    					this.q = tmpQ;
    				}
    			}
    
    			// Get the top element.
    			public int Top ()
    			{
    				int val = 0;
    
    				if (this.q.Count > 0) {
    					var tmpQ = new Queue<int> ();
    					while (this.q.Count > 0) {
    						val = this.q.Dequeue ();
    						tmpQ.Enqueue (val);
    					}
    
    					this.q = tmpQ;
    				}
    
    				return val;
    			}
    
    			// Return whether the stack is empty.
    			public bool Empty ()
    			{
    				return this.q.Count == 0;
    			}
    		}

  • 0

    Sorry I have just fixed this issue. Please try again, it should get accepted now :)


  • 0
    J

    thx. it is working now!


Log in to reply
 

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