大佬们,这题要求复制栈元素,然后再塞到栈顶,只能用一个额外的栈和一个 integer 变量,咋做? 比如 : (Top) 1, 2, 3, 4, 5 (Bottom) ⇒ (Top) 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 (Bottom)
Write a function to duplicate the elements of stack s on top the original elements, by using only one additional queue q (initially empty), and one integer variable m. def dup_sq(s, q):
1
Itoktsnhc 2022-02-22 17:47:14 +08:00 1
额外的队列吧
|
2
withoutconscious OP @Itoktsnhc 对哦,我没看仔细😂,那会做了
|