标签:search leetcode 面试题 算法 algorithm
//store disorder nodes, most of the number is 4. vector<TreeNode*> outorder; //point to the last node of inorder sequence TreeNode *pre = NULL; void visitInorder(TreeNode* root){ if(root == NULL) return; if(root->left) visitInorder(root->left); if(pre == NULL) pre = root; else if(root->val < pre->val){ outorder.push_back(pre); outorder.push_back(root); } //move pre to the new tail. pre = root; if(root->right) visitInorder(root->right); } void recoverTree(TreeNode *root) { if( NULL == root ) return; visitInorder(root); if(outorder.size()) { swap(outorder[0]->val, outorder[outorder.size() - 1]->val); } }
java swing实现小球沿正弦曲线运动的代码,布布扣,bubuko.com
标签:search leetcode 面试题 算法 algorithm
原文地址:http://blog.csdn.net/yaerfeng/article/details/29801381