题解 | #用两个栈实现队列#
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param node int整型 * @return 无 */ static int stack1[1000]; static int stack2[1000]; static int len1 = 0; static int len2 = 0; void push(int node) { stack1[len1] = node; len1++; } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param 无 * @return int整型 */ int pop() { if (len2 == 0) { while (len1 != 0) { len1--; stack2[len2] = stack1[len1]; len2++; } } len2--; return stack2[len2]; }