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

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

最近在做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. Build常见错误

    1.ant 解决com.sun.tools.javac.Main is not on the classpath的问题 在ant打包时报错: 解决com.sun.tools.javac.Main is ...

  2. C Primer Plus(第五版)3

    第三章 数据和 C 在本章中你将学习下列内容: 1. 关键字: int, short, long, unsigned, char, float, double, _Bool, _Complex, _I ...

  3. (easy)LeetCode 235.Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  4. [ZOJ 1008]Gnome Tetravex (dfs搜索 + 小优化)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1008 题目大意:给你n*n的矩阵,每个格子里有4个三角形,分别是 ...

  5. [HDU 3689]Infinite monkey theorem (KMP+概率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3689 黄老师说得对,题目只有做wa了才会有收获,才会有提高. 题意:一个猴子敲键盘,键盘上有n个键,猴 ...

  6. Spring Data Jpa 规范接口表

      Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname ...

  7. OC基础(25)

    NSNumber NSValue NSDate NSFileManager *:first-child { margin-top: 0 !important; } body > *:last-c ...

  8. github入门

    一.先了解 相比CVS\SVN优势: - 支持离线开发,离线Repository- 强大的分支功能,适合多个独立开发者协作- 速度快 github 本地有仓库,储存着所有repository的历史: ...

  9. MatlabR2014a 安装破解详细图文教程(附下载链接(内附CVX工具箱))

    MATLAB和Mathematica.Maple并称为三大数学软件.它在数学类科技应用软件中在数值计算方面首屈一指.MATLAB可以进行矩阵运算.绘制函数和数据.实现算法.创建用户界面.连接其他编程语 ...

  10. 如何去掉有背景图的a标签的边框

    有两种情况: 1.<a href="#" style="background:url(../images/download.png);"></ ...