zoukankan      html  css  js  c++  java
  • 面试题06 判断二叉树后序遍历的结果 [树]

    人理解迭代,神请你来理解递归! 同样的道理 : 大问题拆成小问题,小问题再继续拆,最后一个出口然后全部解决,出口正是最小的子问题的边界处理!
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <vector>
    #include <stack>
    #include <deque>
    #include <queue>
    #include <bitset>
    #include <list>
    #include <map>
    #include <set>
    #include <iterator>
    #include <algorithm>
    #include <functional>
    #include <utility>
    #include <sstream>
    #include <climits>
    #include <cassert>
    #define BUG puts("here!!!");
    
    using namespace std;
    const int N = 105;
    class Node {
    public :
    	int value;
    	Node* lchild;
    	Node* rchild;
    };
    bool res(int *sec, int len) {
    	if(sec == NULL || len <= 0) return false;
    	int root = sec[len-1];
    	int i = 0;
    	for(; i < len-1; i++) {
    		if(sec[i] > root) {
    			break;
    		}
    	}
    	for(; i < len-1; i++) {
    		if(sec[i] < root) return false;
    	}
    	bool left = true;
    	if(i > 0) {
    		left = res(sec, i);
    	}
    	bool right = true;
    	if(i < len-1) {
    		right = res(sec+i, len-i-1);
    	}
    	return (left && right);
    }
    int main() {
    	return 0;
    }
    

  • 相关阅读:
    WordPress在nginx服务器伪静态
    excel根据一列的值匹配另一列
    linux上安装Anaconda并创建python虚拟环境
    python模块学习之numpy
    大数据测试工具
    python学习路线
    spark event log
    夏令时
    spark学习指南
    Yarn和Spark对比
  • 原文地址:https://www.cnblogs.com/robbychan/p/3787170.html
Copyright © 2011-2022 走看看