早上和面试官聊天, 才发现自己的基础下降的有点厉害, 过去那个飘逸写程序的小青年, 如今有点走下坡路了。

可惜我不服,所以要开始做题,把水平恢复上来,能力是最重要的。

最近在做LeetCodeOJ的题,一般般难度,每道题都不需要查资料就可以做出来,感觉还不错,很像面试题的样子。

当然,最好还是做一些ACM OJ的题吧。

题目: Unique Binary Search Trees

讲的是如何判断N节点二叉搜索树最大个数,其实认真想想就知道,只是一个最大子树的题,忘了,重新用笔画推导,应该是 F(n) = ( F(i)*F(n-i-1)  for i = 0; i<n; ++i)。

另外,早上面试官聊天,提到我居然都忘记了switch的用法,简直菜成狗,必须用一用。

class Solution {
public:
int numTrees(int n) {
switch (n)
{
case 0:
return 1;
case 1:
return 1;
case 2:
return 2;
default:
int ret = 0;
for (int i = 0; i<n; ++i)
{
ret += (numTrees(i)*numTrees(n-1-i));
}
return ret;
}
}
};

很简单的题,庆祝一下我回来了。 另外cnblogs 对 Wordpress 的兼容挺好的,不过代码样式还是有点花,调整了一下,换成cnblog自带的插件,嗯,好一些了。

2014年3月1日 Start && Unique Binary Search Trees的更多相关文章

  1. 【LeetCode】95. Unique Binary Search Trees II 解题报告(Python)

    [LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzh ...

  2. [LeetCode] 95. Unique Binary Search Trees II(给定一个数字n,返回所有二叉搜索树) ☆☆☆

    Unique Binary Search Trees II leetcode java [LeetCode]Unique Binary Search Trees II 异构二叉查找树II Unique ...

  3. Unique Binary Search Trees II leetcode java

    题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. F ...

  4. [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  5. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  6. 【LeetCode】95. Unique Binary Search Trees II

    Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...

  7. 【leetcode】Unique Binary Search Trees

    Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...

  8. 【leetcode】Unique Binary Search Trees II

    Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...

  9. 41. Unique Binary Search Trees && Unique Binary Search Trees II

    Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...

随机推荐

  1. RunJS - 在线编辑、展示、分享、交流你的 JavaScript 代码

    发现一个很好玩,很强大的网站 RunJS - 在线编辑.展示.分享.交流你的 JavaScript 代码   http://runjs.cn/ 比如: http://runjs.cn/detail/l ...

  2. Android牟利之道(一)--界面嵌入有米广告

    经过了一番折腾,忙忙碌碌了一下午,终于搞明白了Android软件界面嵌入广告的方法,以下我以嵌入有米广告为例小结一下: 我的新浪微博(wind瑞):http://weibo.com/tianrui19 ...

  3. DIY--主板跳线接法

    如下图:

  4. distinct 多个字段

    select distinct ID,AA,BB from tName与select distinct ID from tName有什么区别??第一种情况,distinct会不会影响AA,或者BB字段 ...

  5. linux命令行与shell脚本编程大全---bash shell命令

    PS1 =“[\t][\u]\$”                  //新的shell提示符显示了当前时间和用户名 在Windows中,你经常看到这样的文件路径:D:\work\FTL moniqi ...

  6. C++学习35 模板中的函数式参数

    C++对模板类的支持比较灵活,模板类的参数中除了可以有类型参数,还可以有普通参数.例如: template<typename T, int N> class Demo{ }; N 是一个普 ...

  7. java学习___File类的创建

    一.使用File创建文件 File file = new File("."+File.separator+"data.dat"); //如果不存在则创建 fil ...

  8. python wechat_sdk间接性的出现错误OfficialAPIError: 40001,说access_token已过期或者不是最新的。

    原因是部署django时使用了多进程,每个进程都会去请求access_token,只有最新的那个有效

  9. python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求

    一.JSON简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programm ...

  10. [技巧]把Excel里的数据插入到数据库里的方法

    .如果先在6行数据的最后一列在插入一列数据,请先把列名写好,然后再第一行的该列下输入数字, 然后选中该单元格向下拖拽一个单元格然后就能看到黑色的小框, 双击右下角黑色的小点,6行数据就 会填上默认的第 ...