LeetCode 二叉树 | 100. Same Tree

来源:互联网 发布:如何出售域名 编辑:程序博客网 时间:2024/04/28 02:20
/* * Leetcode100. Same Tree * Funtion: Given two binary trees, write a function to check if they are equal or not. * Author: LKJ * Date:2016/7/21 * 找两棵数是不是一样的*/#include <iostream>//#include <vector>using namespace std;struct TreeNode {    int            val;    TreeNode*    left;    TreeNode*    right;    TreeNode(int x): val(x), left(NULL),right(NULL) {}};class Solution {public:    bool isSameTree(TreeNode* p, TreeNode* q) {        if( (p == NULL)&&(q == NULL) ){            return true;        }else if( (p != NULL)&&(q == NULL) ){            return false;        }else if( (p == NULL)&&(q != NULL) ){            return false;        }else{            if(p->val != q->val){                return false;            }else{                return (isSameTree(p->left,q->left) && isSameTree(p->right,q->right));            }        }    }};int main(){    //int myin;    //int myout;    //Solution SA;    //cout << "Please Enter" << endl;    //cin >> myin;    //myout = SA.singleNumber(myin);    //cout << myout << endl;    //cout << getFristBit(1) << endl;    return 0;}
0 0
原创粉丝点击