题解 | #用两个栈实现队列#
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
public class Solution {
var stack1: [Int] = []
var stack2: [Int] = []
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param node int整型
* @return 无
*/
func push ( _ node: Int) {
// write code here
stack1.append(node)
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param 无
* @return int整型
*/
func pop () -> Int {
// write code here
if stack2.isEmpty {
while !stack1.isEmpty {
stack2.append(stack1.removeLast())
}
}
return stack2.removeLast()
}
}