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

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

最近在做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. Linux有问必答:怎样解决“XXX is not in the sudoers file”错误

    问题:我想在我的Linux系统上使用sudo来运行一些特权命令,然而当我试图这么做时,我却得到了"[我的用户名] is not in the sudoers file. This incid ...

  2. AI

  3. html table单双行颜色间隔(转载)

    直接上代码: <html> <head> <meta http-equiv="Content-Type" content="text/htm ...

  4. OperationResult

    public class OperationResult<T> { private readonly ConcurrentDictionary<string, T> _valu ...

  5. 第3章 System V IPC

    3.1 概述 System V IPC 包含:System V消息队列.System V信号量.System V共享内存. 3.2 key_t 键和 ftok函数 这三种类型的System V IPC ...

  6. [ActionScript 3.0] AS3.0 获取像素点的灰度

    /** * 获取像素点的灰度 * @color 像素点的颜色值 * @return uint */ function getGray(color:uint):uint { return getR(co ...

  7. Matla学习:figure+axes+plot

    function fig = SetDrawParam() %.获得屏幕尺寸 figpos = , 'ScreenSize');%获得屏幕尺寸,单位像素 %.设置坐标系在画布中的位置,针对不同尺寸或不 ...

  8. 安装LINUX X86-64的10201出现链接ins_ctx.mk错误-转自yingtingkun

    详细错误信息为: Error in invoking target ‘install’ of makefile ‘/opt/oracle/product/10.2/ctx/lib/ins_ctx.mk ...

  9. (easy)LeetCode 258.Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  10. Nginx 内置全局变量

    Nginx在使用过程中,有不少的内置全局变量可以用做条件判断和编程控制,本文总结一些已知的指令,以供参考. $arg_PARAMETER  这个变量包含在查询字符串时GET请求PARAMETER的值. ...