classMyQueue{Deque<Integer> inStack;Deque<Integer> outStack;publicMyQueue(){inStack =newArrayDeque<Integer>();outStack =newArrayDeque<Integer>();}publicvoidpush(int x){inStack.push(x);}publicintpop(){if(outStack.isEmpty()){in2out();}return outStack.pop();}publicintpeek(){if(outStack.isEmpty()){in2out();}return outStack.peek();}publicbooleanempty(){return inStack.isEmpty()&& outStack.isEmpty();}privatevoidin2out(){while(!inStack.isEmpty()){outStack.push(inStack.pop());}}}/*** Your MyQueue object will be instantiated and called as such:* MyQueue obj = new MyQueue();* obj.push(x);* int param_2 = obj.pop();* int param_3 = obj.peek();* boolean param_4 = obj.empty();*/
遇到报错one of the variables needed for gradient computation has been modified by an inplace operation。意思是对输入x原地操作(inplace operation),一个变量在反向传播过程中被修改了,而不是按照预期的版本(ve…