zoukankan      html  css  js  c++  java
  • 剑指office--------栈的压入、弹出序列

    题目描述

    输入一颗二叉树的根节点和一个整数,按字典序打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。
     
     
     
     
     1 class Solution {
     2 public:
     3     bool IsPopOrder(vector<int> pushV,vector<int> popV) {
     4         int len=pushV.size(),pos=0,r=0,i=0;
     5         int q[len+10];
     6         while (pos<len){
     7             if (r==0){
     8                 q[r++]=pushV[i++];
     9                 continue;
    10             }
    11             if (q[r-1]!=popV[pos]){
    12                 if (i<len)
    13                     q[r++]=pushV[i++];
    14                 else
    15                     break;
    16             }
    17             else{
    18                 pos++;
    19                 r--;
    20             }
    21         }
    22         if (pos==len)    return true;
    23         else    return false;
    24     }
    25 };
     
     
  • 相关阅读:
    with
    网编
    选课新系统大作业
    网络编程

    知识点
    Python
    学生选课大作业
    理解position与anchorPoint[转]
    毛玻璃效果的简单使用
  • 原文地址:https://www.cnblogs.com/q1204675546/p/13362563.html
Copyright © 2011-2022 走看看