![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法(树)
Just Go For It Now
这个作者很懒,什么都没留下…
展开
-
求解x的n次方
解法一(简单模拟) int function1(int x, int n) { int result = 1; // 注意 任何数的0次方等于1 for (int i = 0; i < n; i++) { result = result * x; } return result; } 解法二(递归) int function4(int x, int n) { if (n == 0) { return 1; } .原创 2021-02-22 11:54:15 · 1077 阅读 · 1 评论 -
用迭代法遍历二叉树
基于迭代法的二叉树中序遍历 vector<int> inorderTraversal(TreeNode* root) { vector<int> result; stack<TreeNode*> st; TreeNode* cur = root; if(root!=NULL) st.push(root); while(!st.empty()){ TreeNode* no原创 2021-02-22 10:00:43 · 103 阅读 · 0 评论