![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
recursion
USC_ECE
这个作者很懒,什么都没留下…
展开
-
JZ26 二叉搜索树与双向链表
https://leetcode-cn.com/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/solution/mian-shi-ti-36-er-cha-sou-suo-shu-yu-shuang-xian-5/采用中序遍历来做。需要注意的是牛客网不需要我们把头和尾相连接。代码如下:/**public class TreeNode { int val = 0; TreeNode left = null;原创 2020-09-06 22:09:59 · 315 阅读 · 0 评论 -
JZ23 二叉搜索树的后序遍历序列
https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/solution/mian-shi-ti-33-er-cha-sou-suo-shu-de-hou-xu-bian-6/代码如下:public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { // Corner Case原创 2020-08-31 23:15:44 · 169 阅读 · 0 评论 -
Leetcode 231/326/342. Power of Two/Three/Four
这类题都可以用一种recursive的方法去解决,下面以342为例:首先是Base Case: 如果 num <= 0, 则num不是4的幂;如果num == 1,则num是4的幂.然后是Recursive Rule: 如果num不是4的倍数,则num不是4的幂;如果num是4的倍数,则继续检查num / 4是否为4的幂。class Solution { public boolean isPowerOfFour(int num) { if(num <= 0)原创 2020-06-05 11:02:34 · 109 阅读 · 0 评论 -
LeetCode 50. Pow(x, n)
这道题就是一个简单地recursive题,唯一需要注意的点是Integer.MIN_VALUE的相反数超出了int类型能表示的最大值,所以我们需要先用long数据类型把int n 存下来,在使用取反操作。class Solution { public double myPow(double x, int n) { // -2147483648 would cause overflow because it does not // have opposite n原创 2020-06-05 09:48:27 · 158 阅读 · 3 评论