- 博客(22)
- 资源 (3)
- 收藏
- 关注
原创 Leetcode---Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2015-04-12 13:59:56 380
原创 Leetcode---Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX X
2015-04-12 12:58:27 530
原创 彻头彻尾的理解回溯算法
定义在程序设计中,有相当一类求一组解,或求全部解或求最优解的问题,例如读者熟悉的八皇后问题,不是根据某种特定的计算法则,而是利用试探和回溯的搜索技术求解。回溯法也是设计递归过程的一种重要方法,它的求解过程实质上是一个先序遍历一棵"状态树"的过程,只是这棵树不是遍历前预先建立的,而是隐含在遍历过程中。---《数据结构》(严蔚敏)怎么理解这段话呢?首先,某种问题的解我们很难去找规律计算
2015-04-12 08:29:33 21497 3
原创 Leetcode---N-Queens II
N皇后问题,求数量,比记录轨迹简单。int N;int sum;vector > m;bool check(int row,int column){ if(row==1) return true; int i,j; for(i=0;i<=row-2;i++){ if(m[i][
2015-04-11 17:18:42 471
原创 Leetcode---N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.著名的n皇后问题,要求记录摆放位置,下面几行是关键:void dfs(int level){ if(level==N){
2015-04-11 17:11:45 376
原创 Leetcode---Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.给后序序列和中序序列,求二叉树。这个怎么说呢,和上一道题如出一辙,只不过是顺序变了,简单!TreeNode * f(vector &inorder, vector &postorder, int inl,int inr,int p
2015-04-11 10:38:48 443
原创 Leetcode---Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.由树的前序遍历序列和中序遍历序列构建二叉树1. 在中序序列中找到根节点2. 把中序序列拆分成左右两个中序序列3. 找对应的前序序列,注意,对应的中序和前序序列长度相同4. 递归TreeNode *buildTree(ve
2015-04-11 10:34:06 504
原创 Leetcode---Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.这个有所变化,是要求输出卡特兰数的结果,可以用DFS。以每个节点作为树的根节点,生成一系列对应的二叉树。 vector generateTrees(int n) { re
2015-04-11 09:50:45 364
原创 Leetcode---Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?很简单,就是求卡特兰数,直接公式求 int numTrees(int n) { vector num(n+1); num[0]=1; num[1]=1; num[
2015-04-11 09:47:55 394
原创 浅谈Binder的基本原理
网上有一堆关于Binder原理的文章,都很长,我希望能尽量把这个问题讲得简短些。1)关于binder驱动Binder在Android里被设计成了一个驱动,安装在/dev/binder,这也是Android和linux的重要区别之一:Android提出了一个新的进程间通信方式(IPC)。另外,这种方式是通过远程过程调用(RPC)实现的。对Binder的操作和对其它驱动的操作是一样的,
2015-04-11 09:24:40 595
原创 Leetcode---Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()
2015-04-06 18:20:46 433
原创 Leetcode---Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].Show Tags
2015-04-06 18:17:52 342
原创 Leetcode---Subsets
Given a set of distinct integers, S , return all possible subsets.Note: Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exam
2015-04-06 18:09:25 445
原创 Leetcode---Clone Graph
这道题可以用DFS和BFS分别完成。要说DFS和BFS讲的透彻的,还是算法导论,下面给出算法导论上的伪代码,注意,其中任何一行code都是非常值得玩味的:BFS伪代码BFS(G, s) 1 for each vertex u ∈ V [G] - {s} 2 do color[u] ← WHITE 3 d[u] ← ∞ 4
2015-04-06 17:44:37 366
原创 Leetcode---Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota
2015-04-06 17:38:22 418
原创 Leetcode---word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "
2015-04-06 17:33:19 473
原创 Leetcode---Recover Binary Search Tree
一个二叉排序树的某两个节点颠倒了为了,去恢复它。不可思议的是这道题居然被标记为了hard,其实难度远低于其他的hard或medium。思路:中序遍历,然后看是不是递增的,如果不是,记录下来。注意,可能有一次逆序,也可能有两次,一次的发生在相邻节点。注意,中序遍历是这样的:void f(node * root){if(root==NULL)return;f
2015-04-06 17:32:42 575
原创 Android Framework层线程设计
framework层的thread是c++实现的,定义在utils/threads.h,实现在Threads.cpp (system\core\libutils)。首先看看定义:class Thread : virtual public RefBase{public: // Create aThread object, but doesn't create or start
2015-04-03 22:07:25 1011
原创 Android音量设置流程干货版
1. 音量级数定义在AudioService.java中定义了最大音量MAX_STREAM_VOLUME,手机的设置property可以覆盖它。2. 音量初始化initStreamVolume传入AudioPolicyManagerBase里的StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES];3.
2015-04-03 22:04:20 3554
原创 DSD音频基本原理
DSD采用脉冲密度调制(Pulse-densitymodulation),对应于PCM的pulse-codemodulation。信号表现为delta-sigma编码。采样率为2.8224M,但是采样精度是1bit(2.8224M=44.1K*64)。脉冲密度调制中,bit1代表+A(某一个正数),bit0代表-A(某一个负数),于是数学上,就可以表示为:其中x[n]是振幅,而
2015-04-03 21:50:47 7739
原创 I2S,PCM,IOM-2,I2C,SPI,UART,GPIO
概述I2S,PCM,IOM-2都是数字音频接口,传数据的。I2C,SPI,UART,GPIO是控制接口,传控制信令的。I2SI2S(Inter-IC Sound Bus)是飞利浦公司为数字音频设备之间的音频 数据传输而制定的一种总线标准。 I2S至少3根线:1. 比特时钟线首先解释一下比特时钟线。比特时钟线上对每个bit有一个脉冲,比特时钟频率是采样率
2015-04-03 21:37:49 3537
原创 工厂模式
1 什么是工厂模式?以下摘自维基百科工厂方法模式(英语:Factorymethod pattern)是一种实现了“工厂”概念的面向对象设计模式。就像其他创建型模式一样,它也是处理在不指定对象具体类型的情况下创建对象的问题。工厂方法模式的实质是“定义一个创建对象的接口,但让实现这个接口的类来决定实例化哪个类。工厂方法让类的实例化推迟到子类中进行。”创建一个对象常常需要复杂的过程
2015-04-03 21:04:20 856
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人