自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(12)
  • 收藏
  • 关注

原创 [leetcode] dp

1-D DP:Climbing Stairs:Naive 就是sum[0]; if (n==0) sum[0]++;然后climbstairs(n-1)climbstairs(n-2) public int climbStairs(int n) { if (n<=0) return 0; if (n==1) return 1;

2015-01-11 17:05:03 319

原创 [leetcode] math

permutation sequence (find kth permutation sequence)* 要知道每个position的数是k/(n-1)!* 用过的element要去掉,所以要新建一个list里面有一列数*开始要k--来match list里面的element public String getPermutation(int n, int k) {

2015-01-11 13:22:56 314

原创 [leetcode] backtracking

79 Word Search (复杂度 exponential) :经典dfs & backtracking:在board的每个位置做dfs search, dfs用boolean[][] 做backtracking:base case:如果对了就return true; invalid || not match就return false public boolean exist(char[

2015-01-11 09:56:45 429

原创 算法复杂度总结

栗子:word break: 1. naive approach: O(2^n)iterate through the length of the string, and call recursively每个字母间隙选择分开还是不分开,所以是2^n2.dp:O(n^2)top-down || bottom-upbottom-up: 比较好想,两个for loop

2015-01-10 21:23:32 302

原创 dfs

一些dfs的集合:Symmetric Tree:1. 左边val==右边val2.左边的左边 same 右边的右边;左边的右边 same 右边的左边public class Solution { public boolean isSymmetric(TreeNode root) { if (root==null) return true; r

2015-01-10 14:59:34 304

原创 [leetcode] Validate Binary Search Tree dfs

方法1: inorder traversal, 如果in order就是valid (用int[] 做publicly accessible place,就不能过min_value, 这样的话就要用arraylist,然后放null)方法2: 按definition构建recursion, left: helper(root.left, min, root.val);right: help

2015-01-10 14:16:07 257

原创 [leetcode] Level Order Traversal

Level Order Traversal, 代表性的bfs几个维护的量:1. queue curLevel2. queue nextLevel3. List item 当前level的东西/** * Definition for binary tree * public class TreeNode { * int val; * Tre

2015-01-10 14:05:21 262

原创 [leetcode] 133 clone graph bfs

bfs:1. 一个HashMap来找对应的cloned node2. 一个queue来装frontier3. 一边建node一边连接node/** * Definition for undirected graph. * class UndirectedGraphNode { * int label; * List neighbors; *

2015-01-10 13:25:16 272

原创 [leetcode] 130 surrounded regions dfs bfs

这题的做法:1. 把外面一圈的每一个o都traverse一下(bfs,dfs 都可以),把它们mark成第三种字母y2. 把整个board跑一遍,看到o就变成x, 看到y就变成o要注意的点:1. 这里在做dfs/bfs的时候不需要用visited,只需要在if里查board[i][j]=='O'就行,因为visited已经被mark成y了。2. bfs时保存坐标点用 i

2015-01-10 12:57:17 336

原创 [leetcode] 126 Word Ladder ii bfs dfs

大致框架:用bfs,从start开始,建一个图,parent node连接着可以变到的node (aka. in dict || ==end)与word ladder 区别: 1. 没有了global value ===> 每个node 包含了对应的lvl2. 两个queue变成一个queue ===> node里有对应的lvl 不再需要两个queue3. HashSet visi

2015-01-10 08:04:28 357

原创 [leetcode]127 Word Ladder BFS

要maintain的量:int level, Queue curLevel, Queue nextLevel, Set visited两个check curLevel 的loop,里面对每个char position进行从a-z的调换,查1)是不是end, 是就return level+1;   2) 在dict, 没在visited就加nextLevel要注意的地方:1) 找到了

2015-01-09 23:38:08 328

原创 [CC]Ch18 Suffix Tree<<<TO DO

[CC]Ch18 Suffix Tree<<<TO DO

2015-01-09 16:10:36 277

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除