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;
    }
    

  • 相关阅读:
    关于struts页面跳转的问题
    java中==和equals的区别
    控制广播风暴的方法
    广播风暴的成因及解决办法
    思科FEX配置
    思科vPC技术和配置
    数据中心架构TOR和EOR
    ARP表项及老化时间
    MAC地址表和老化时间
    track 3 list boolean or
  • 原文地址:https://www.cnblogs.com/robbychan/p/3787170.html
Copyright © 2011-2022 走看看