2023-08-07力扣今日三题

链接:

剑指 Offer 31. 栈的压入、弹出序列

题意:

给定入栈序列和出栈序列,求出栈序列是否可能

解:

模拟就vans了

实际代码:

#include
using namespace std;
bool validateStackSequences(vector& pushed, vector& popped)
{
    stacktemp;int popindex=0,lg=pushed.size();
    for(int i=0;i pushed,popped;int temp;
    while(cin>>temp) pushed.push_back(temp);
    cin.clear();
    while(cin>>temp) popped.push_back(temp);
    bool ans=validateStackSequences(pushed,popped);
    cout<

限制:

  • 0 <= pushed.length == popped.length <= 1000
  • 0 <= pushed[i], popped[i] < 1000
  • pushed 是 popped 的排列。

你可能感兴趣的:(力扣每日一题,leetcode,c++)