我的代码游记

标签 · 递归

首页

关于

归档

loading..
LeetCodeEasy递归二叉树

226.Invert Binary Tree(Easy)

Invert a binary tree.反转二叉树 *  基本上二叉树的玩意儿用递归都能做* For example to My Solution(Java) Version 1  Time: 1ms:  简单地递归然后调换左右子树 /**  * Definition for a binary tree node.  * public class TreeNode {  *     int val;  *     TreeNode left;  *     TreeNode right;  *     TreeNode(int x) { val = x; }  * }  */ public class Solution {     public T..

更多
LeetCodeEasy递归

70.Climbing Stairs(Easy)

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?你在爬楼梯,楼梯总共有n个台阶,每次你可爬一级或者两级台阶,问爬完整个楼梯有多少种爬的方式? *  这是以前小学的奥数题,找规律,爬楼梯,显然我们都知道对于一次只走一级或者两级的情况是符合斐波那契数列的,所以题目的答案就变成了求第n个斐波那契数是多少* My Solution(Java) Version 1 Time: 0ms:  应该是因为是Easy题,所以测试的样例相当少,求..

更多
计数LeetCodeMedium递归二叉树

222.Count Complete Tree Nodes(Medium)

Given a complete binary tree, count the number of nodes.给定一个完全二叉树,计算其节点数 **Definition of a complete binary tree from Wikipedia:**In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h. *  难度在于其如何优..

更多
计数LeetCodeMedium递归

241.Different Ways to Add Parentheses(Medium)

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+ ,- and*.给定一个数字和运算符的字符串,返回所有不同分组情况下运算的结果。合法的运算符有+,-和* *  题目的意思就是给一段只有+,-,*的三则运算,然后加括号,加括号的时候符号不变,把加了括号后计算的不同结果列出来* Example 1 Input:”2-1-1”.((2-1)-1) = 0(2-(1-1)) = 2Output:[0, 2] Exa..

更多