2014年3月1日 Start && Unique Binary Search Trees
早上和面试官聊天, 才发现自己的基础下降的有点厉害, 过去那个飘逸写程序的小青年, 如今有点走下坡路了。
可惜我不服,所以要开始做题,把水平恢复上来,能力是最重要的。
最近在做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的更多相关文章
- 【LeetCode】95. Unique Binary Search Trees II 解题报告(Python)
[LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzh ...
- [LeetCode] 95. Unique Binary Search Trees II(给定一个数字n,返回所有二叉搜索树) ☆☆☆
Unique Binary Search Trees II leetcode java [LeetCode]Unique Binary Search Trees II 异构二叉查找树II Unique ...
- Unique Binary Search Trees II leetcode java
题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. F ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- 【LeetCode】95. Unique Binary Search Trees II
Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...
- 【leetcode】Unique Binary Search Trees
Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...
- 【leetcode】Unique Binary Search Trees II
Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...
- 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 ...
随机推荐
- laravel下使用阿里云oss上传图片
对小公司而言,使用阿里云oss比直接买硬盘要划算的多,不管从存储性价比上还是从网速负载上.最近因为公司的项目有比较大的图片存储访问需求,所以决定使用阿里云的oss. 在研究了一下以后,摆着不自己造轮子 ...
- gridView自动列宽代码
gridView1.OptionsView.ColumnAutoWidth = false; for (int I = 0; I < gridView1.Columns.Count; I++) ...
- 强大的JS数组
1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...
- 理解perl的编码转换——utf8以及乱码
工作需要,闲暇之余,仔细研究了一下脚本乱码的问题 1. vim新建的文件 1)在linux命令行 vim命令建立的文件,如果内容中不出现中文,默认是ASCII.那么用notepad++打开的时候,就是 ...
- 解决CI框架的Disallowed Key Characters错误提示
用CI框架时,有时候会遇到这么一个问题,打开网页,只显示 Disallowed Key Characters 错误提示.有人说 url 里有非法字符.但是确定 url 是纯英文的,问题还是出来了.但清 ...
- 89、Android EditText 悬浮停靠
package com.willen.topFloatDemo; import android.content.Context; import android.os.Handler; import a ...
- [ActionScript 3.0] AS3调用百度天气预报查询API
接口说明 根据经纬度/城市名查询天气的结果 接口示例 http://api.map.baidu.com/telematics/v3/weather?location=成都&output=jso ...
- 朗逸2011款 1.4t 清除保养告警灯
朗逸2011款 1.4t 清除保养告警灯 Posted on 2015-03-01 21:06 编辑 仪表盘上有两个按钮 按住右边set键,钥匙旋转到通电状态,保持2s. 放掉set,按左边的切换按钮 ...
- mysql数据库同步
mysql数据库同步 1.1. Master 设置步骤 配置 my.cnf 文件 确保主服务器主机上my.cnf文件的[mysqld]部分包括一个log-bin选项.该部分还应有一个server-i ...
- excel数据通过构建sql语句导入到数据库中
拿到一张excel数据表格,数据格式如下图所示: 2.根据excel数据结果,构建保存excel数据的表结构 CREATE TABLE #tmpExcel(IP VARCHAR(100),IPAddr ...