given a stack which can keep m numbers at most. push n numbers in the order of 1, 2, 3, ..., n and pop randomly. you are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. for example, if m is 5 and n is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, but not 3, 2, 1, 7, 5, 6, 4.
时间: 2023-05-01 13:03:05 浏览: 107
Fullstack Vue 3_ The Complete Guide to Vue.js
这个题目描述了一个场景:给定一个最多可以容纳m个数的栈,按1,2,3,……,n的顺序压入n个数,并随机弹出。你需要判断给定的数字序列是否可能是该栈的弹出序列。例如,当m为5,n为7时,我们可以从栈中获得1,2,3,4,5,6,7,但不能获取3,2,1,7,5,6,4。
阅读全文