??xml version="1.0" encoding="utf-8" standalone="yes"?>在线视频中文亚洲,岛国av在线播放,国产免费a∨片在线观看不卡http://www.aygfsteel.com/menglee/archive/2016/11/13/431980.htmlMeng LeeMeng LeeSat, 12 Nov 2016 16:45:00 GMThttp://www.aygfsteel.com/menglee/archive/2016/11/13/431980.htmlhttp://www.aygfsteel.com/menglee/comments/431980.htmlhttp://www.aygfsteel.com/menglee/archive/2016/11/13/431980.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/431980.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/431980.html
本文介绍了包?Python、Java、Haskell{在内的一pd~程语言的深度学习库?br />
Python
  • Theano是一U用于用数列来定义和评估数学表辄 Python 库。它可以?Python 中深度学习算法的~写更ؓ单。很多其他的库是?Theano 为基开发的?/span>
  • Caffe是一U以表达清晰、高速和模块化ؓ理念建立h的深度学习框架。它是由伯克利视觉和学习中心QBVLCQ和|上C֌贡献者共同开发的。谷歌的 DeepDream 人工囑փ处理E序正是建立?Caffe 框架之上。这个框架是一?BSD 许可的带?Python 接口?C++库?/span>
  • nolearn包含大量其他经|络库中的包装器和抽象(wrappers and abstractionsQ,其中最值得注意的是 LasagneQ其中也包含一些机器学习的实用模块?/span>
  • Genism是一个部|在 Python ~程语言中的深度学习工具包,用于通过高效的算法处理大型文本集?/span>
  • Chainerq接深度学习中的法与实玎ͼ它强劌Ӏ灵z而敏锐,是一U用于深度学习的灉|的框架?/span>
  • deepnet是一U基?GPU 的深度学习算法的 Python 实现Q比如:前馈经|络、受限玻兹曼机、深度信늽l、自~码器、深度玻兹曼机和卷U神l网l?/span>
  • Hebel是一个在 Python 中用于带有神l网l的深度学习的库Q它通过 PyCUDA 使用带有 CUDA ?GPU 加速。它可实现大多数目前最重要的神l网l模型,提供了多U不同的Ȁzd数和训练方式Q如动量QNesterov 动量Q退出(dropoutQ和 前期停止Qearly stoppingQ?/span>
  • CXXNET是一U快速,明的分布式深度学习框Ӟ它以 MShadow 为基。它是轻量可扩展的 C++/CUDA 经|络工具包,同时拥有友好?Python/Matlab 界面Q可供机器学习的训练和预用?/span>
  • DeepPy是一U徏立在 Mumpy 之上?Python 化的深度学习框架?/span>
  • DeepLearning是一个用 C++?Python 开发的深度学习库?/span>
C++
  • eblearn是一个机器学习的开?C++库,qU大学机器学习实验室?Yann LeCun 牵头研发。尤其是Q按?GUI、演C和教程来部|的带有Z能量的模型的L经|络?/span>
  • SINGA被设计用来进行已有系l中分布式训l算法的普通实现。它?Apache Software Foundation 提供支持?/span>
Java
  • N-Dimensional Arrays for Java (ND4J)是一Uؓ JVM 设计的科学计库。它们被应用在生产环境中Q这意味着路径被设计成可以最的 RAM 内存需求来快速运行?/span>
  • Deeplearning4j是第一个ؓ Java ?Scala ~写的消费开元分布式深度学习库。它被设计成在商业环境中使用Q而非研究工具?/span>
  • Encog是一U先q的机器学习框架Q支持支持向量机QSupport Vector MachinesQ,人工经|络QArtificial Neural NetworksQ,基因~程QGenetic ProgrammingQ,贝叶斯网l(Bayesian NetworksQ,隐马科夫模型(Hidden Markov ModelsQ和 遗传法QGenetic AlgorithmsQ?/span>
Lua
  • Torch是一U科学计框Ӟ可支持多U计机学习法?/span>
Haskell
  • DNNGraph是一个用 Haskell ~写的深度神l网l生?DSL?/span>
.NET
  • Accord.NET是一U?NET 机器学习框架Q包含声韛_囑փ处理库,它完全由 C# ~写。它是一Uؓ开发生产的计机视觉、计机听觉、信号处理和l计应用而设计的完整框架?/span>
R
  • darch包可以用于徏立多层神l网l(深层l构Q。其中的训练方式包括使用Ҏ发散法进行提前训l,或用通常的训l方法(如反向传播和p梯度Q进行一些微调?/span>
  • deepnet实现了一些深度学习架构和经|络法Q包?BP、RBM、DBN、深度自~码器等{?/span>


Meng Lee 2016-11-13 00:45 发表评论
]]>
我是如何q入hhttp://www.aygfsteel.com/menglee/archive/2014/06/13/414689.htmlMeng LeeMeng LeeThu, 12 Jun 2014 18:00:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/06/13/414689.htmlhttp://www.aygfsteel.com/menglee/comments/414689.htmlhttp://www.aygfsteel.com/menglee/archive/2014/06/13/414689.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/414689.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/414689.html今天Q终于有旉静下心来回顾q去两年来所做的事情Q感慨万千,一时之间竟不知从何说v。两q以来,遇到的困隄实不,但每每遭遇挫折与不顺之后Q却往往能柳暗花明,遇到新的转机Q?/span>让我真真切切地感受到了功夫不负有心hq句话的含意?/span>

一、ؓ什么要出国
其实Q之前从来没有考虑q要出国Q更没有惌能直接出国工作?/span>回想一下,q个军_的做出,多半q是~于自己骨子里的不安分?/span>我从很大E度上来说是一个闲不住的hQ从学、中学?/span>大学到研I生Q我几乎每天都有明确的目标。然而,2013q从公司C业单位工作以后,我的生活发生了巨大地转变。简单的工作、空z的公文?/span>无聊的活动占据了我全部的工作d?/span>有段旉几乎天天写材料搞zd。领导经常夸我材料写得又快又好,zd也搞得有声有Ԍ心里感觉很有成就感。然而,旉一长,逐渐发现那些公文永远是一个套路,以至于我分门别类Q?/span>摸烦Z几个万能模板。而活动则千篇一律,让h疲于应付?/span>我甚臛_以看到六十岁退休时我在q什么,于是一阉|惧感常常会莫名袭来,因ؓ我不安分、不满于此?/span>我不能放弃所学所长,我不能庸庸碌在q里度过未来的几十年Q?/span>我还有梦惻I我还要登高看世界。ؓ了这个,我走q了不^凡的两年?/span>

二、如何出?/span>
对于普通h来说Q出国大致有三条路?/span>
W一条\是申请去国外留学Q?/span>取得学位之后以应届毕业生的n份找工作Q然后留在国外生zR?/span>q是一条比较稳妥、简便的路,走这条\的h最多?/span>
W二条\是先q入跨国公司的中国分公司工作一D|_然后找机会外zֈ国外总部工作。走q条路的要求比较多,首先要能够进入比较大的跨国公司工作,其次q个公司愿意中国员工transfer到国外,同时q要外国总部有部门愿意接收你Q所以还是需要一些运气?/span>但是Q如果成功,好处也显而易见。省MM的时间和学费Q?/span>降低了家庭负担,对于家境一般的人是非常好的选择?/span>
W三条\是直接参加外国公司的面试Q通过之后直接d外工作?/span>q条路要求最高,需要通过外国公司严格的面试,另外q要能够成功取得{证Q美国工作签证就需要抽{)。因此,走这条\更需要实力、机遇和q气?/span>
鉴于W三条\非常难走Qؓ了保证成功,我选择了同时申请学校和参加外国公司面试的办法,q也注定了我付出更多的艰苦努力?/span>

三、申请学?/span>
甌学校从准备到最l完成,我大概用了一q时间?/span>光参加了三ơGRE和一ơ托考试。回惛_备的q程Q?/span>最大的敌h是自己Q最重要的法宝就是坚持坚持再坚持?/span>记得W一ơ考GRE没有取得理想的成l,因ؓ是第一ơ参加英语考试Q心情非常失落。幸亏当时有x友(现在的老婆Q的鼓励Q我l箋复习没有攑ּ。经q一个月的复习,取得了非怸错的托福成W。记得托出成W的那天,我紧张得不敢查,点开面的那一刻,我都不敢怿居然能有q么不错的成l。特别是听力Q?/span>考试的时候觉得好几个都没有听清楚Q最后居然有27分,真是不可思议Q可见功夫不负有心hQ付出L回报的?/span>
有了p成W之后Q就是撰写申h书。这斚w我完全没有经验,所有的信息全部是通过一亩三分地论坛获得的?/span>q个论坛信息非常丰富Q基本上所有申L关的内容都有涉及?/span>我每天都会花一些时间浏览别人的帖子Qؓ自己定位选校Q?/span>找文书灵感等{。非常感谢我的本U和研究生导师,q有蒋志诚ؓ我递推荐信Q没有你们的帮助Q?/span>我不可能完成甌工作?/span>
最后,我申请了国和加拿大的十五所学校的计机专业的研I生Q?/span>拿到了CMU、USC和多伦多大学的offer。其中,CMU的Data Science program应该是世界数一C的,录取率非怽Q?/span>毕业后的d也非常好Q大多数都可以进入美国一公司工作?/span>多大也是加拿大排名第一的学校,计算机的׃也非常好?/span>

四、Facebook的面?/span>
参加Facebook的面试也完全是无意的Q?/span>在Linkedin上收CFacebook HR的邀请信Q于是也没有怎么准备做了电面,居然反馈非常好,马上q我安排了onsite面试Q地Ҏ印度的v得拉巴?/span>但是Q始l是没有做什么准备,而且和谷歌不一L是,HR办事效率实在太高Q每一轮间隔都非常短,D我根本没有时间热w一下,qleetcode都没有做q就匆匆参加面试了,最l没有如愉K过面试?/span>
不过Q这ơ面试还是很有收莗第一ơ出国,W一ơ参加美国公司全英文面试Q学C太多Q积累了l验Q?/span>可以说如果没有Facebook的失败,我是不可能进入谷歌的?/span>

五、Google的面?/span>
参加h的面试可以说完全是老婆的怂恿?/span>从印度参加完Facebook面试回来之后Q?/span>我就开始专心于学校甌了。但是,老婆我试试面一下Google?/span>׃Facebook的失利和Googleq乎苛刻的面试流E,我开始是抗拒参加的。最后,在老婆的一再要求下Q?/span>我终于找了一个在h上v工作的师兄做了内推?/span>四月底我收到了谷歌北京HR的第一通电话,也正式拉开了我为期一q的面试程?/span>
和HR通电话不久,我进行了W一ơ电话面试?/span>h的电话面试和Facebook差不多,是面试官打q来Q?/span>把题目口qƈ且写在Google Doc上,然后我把E序写在Google Doc上。第一ơ电面的题目不难Q?/span>但谷歌对代码效率和清晰度的要求远q超Z我的惛_?/span>W一轮面得磕绊l,但是q好面试官是中国人,非常niceQ?/span>没有让我fail?/span>
于是Q我又被要求q行W二ơ电面。期间由于面试官临时有事爽约Q?/span>我等了差不多一个月。但是,也就是这一个月Q?/span>我努力做了一些准备,虽然面试依旧不是十全十美Q?/span>但是我还是有惊无险地q入Consite面试环节?/span>
虽然可以onsite面试了,但是我依旧对q入h不报M希望Q因为我清楚的知道,h面试实在是太难了Qonsite面试的挑战将q远大于电面?/span>因此Q我d京面试完全是惛_一ơ免Ҏ游?/span>面试前一天还怹不见的万威夫妇吃饭,聊得很开心,完全没有把面试放在心上?/span>
也许是放杄原因Q我前一天晚上睡得很好,W二天我_非常好?/span>
不过h毕竟是谷歌,面试W一轮一上来q了我一个下马威?/span>一个coding题一个设计题Q表面上很简单,但是做出来L有这样那L问题Q?/span>W一轮完了之后我基本打算回家了?/span>
但是Q不知道Z么,从第二轮开始,p来越利Q?/span>coding做得非常好,基本上是一ơ写完,没有涂改Q?/span>也没有被面试官找到大的bug。突然之_隐隐感觉出现了一丝希望?/span>
四轮q后Q我l束了第一ơonsite面试。但是,三天之后Q?/span>我被告知׃设计题做得不好,我被要求q行一ơ加面,地点在上于是,我又在上做了一ơ面试,只有一个设计题?/span>我感觉答得还可以Q但是心情真的是忐忑不安Q?/span>特别是接下来的一个礼拜,几乎是坐立不安?/span>
记得是一个礼拜之后的C拜五中午,我正做准备主持下午的道d讲堂Q突然接C一?10的电话,我知道是h的电话。接通电话的那一刻,I气都几乎要凝固了,当听到通过HC的消息时Q我Ȁ动得不能自已?/span>不可能完成的d居然完成了,虽然不知道能不能ȝ国总部工作Q?/span>但是能进入谷歌已l非怸Ҏ了,而且h非常鼓励transferȝ国工作,因此Zq是很多的?/span>
然而,让我没有惛_的是Q接下来的team match却异常艰难,陆陆l箋几个team都没有成功match上?/span>转眼到?014q春季,半年的等待让我对何时q入h非常悲观Q?/span>加上甌学校工作十分J重Q我基本没有xq个事情?/span>
在我快要放弃的时候,拿到了美国一个公司的offerQ?/span>他们{应l我办H1B{证。于是,我把q个情况告诉了谷歌,要求他们快l找到teamQ不然我去国了?/span>l果h居然在三天之内ؓ我match上了英国office的一个teamQ让Z得不感叹q是要offer多才好啊Q于是,我又l过了近三个月的{证办理程Q终于要启程赴英了?/span>

回顾两年来的努力Q终于要实现自己的梦想了Q感慨万千?/span>在短短的人生中,能有q一D不d的经历,我觉得十分幸q?/span>展望未来Q我惌万卷书不如行万里路,未来希望能够利用在u敦工作的ZQ尽量多Lz各国走赎ͼ丰富自己的阅历,开拓自q眼界?/span>

最后要感谢老婆一直以来的支持和鼓励,你一直是我前q的动力Q?/span>其次要感谢父母的不理解和不支持,你们的反对让我更加完善了自己的计划,逼着我找C一条最好的\Q还要感谢师长和朋友们的帮助Q?/span>感谢杨老师和沈老师q有蒋志诚不厌其烦地帮我递推荐信Q?/span>感谢万威夫妇多次在北京款待我Q没有你们的食Q?/span>我是不可能完成面试的Q还有许多帮助过我的人,在这里就不能一一感谢了?/span>


Meng Lee 2014-06-13 02:00 发表评论
]]>
[Leetcode] Trapping Rain Waterhttp://www.aygfsteel.com/menglee/archive/2014/01/14/408898.htmlMeng LeeMeng LeeTue, 14 Jan 2014 01:16:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/14/408898.htmlhttp://www.aygfsteel.com/menglee/comments/408898.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/14/408898.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408898.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408898.html法很简单,核心思想是:Ҏ个值A[i]来说Q能trapped的最多的water取决于在i之前最高的值leftMostHeight[i]和在i双的最高的值rightMostHeight[i]。(均不包含自nQ。如果min(left,right) > A[i]Q那么在iq个位置上能trapped的water是min(left,right) – A[i]?/div>
有了q个x好办了Q第一遍从左到双数lleftMostHeightQ第二遍从右到左计算rightMostHeightQ在W二遍的同时可以计出i位置的结果了Q而且q不需要开I间来存放rightMostHeight数组?/div>
旉复杂度是O(n)Q只扫了两遍?br />
 1 public class TrappingRainWater {
 2     public int trap(int A[], int n) {
 3         if (n <= 2)
 4             return 0;
 5 
 6         int[] lmh = new int[n];
 7         lmh[0] = 0;
 8         int maxh = A[0];
 9         for (int i = 1; i < n; ++i) {
10             lmh[i] = maxh;
11             if (maxh < A[i])
12                 maxh = A[i];
13         }
14         int trapped = 0;
15         maxh = A[n - 1];
16         for (int i = n - 2; i > 0; --i) {
17             int left = lmh[i];
18             int right = maxh;
19             int container = Math.min(left, right);
20             if (container > A[i]) {
21                 trapped += container - A[i];
22             }
23             if (maxh < A[i])
24                 maxh = A[i];
25         }
26         return trapped;
27     }
28 }


Meng Lee 2014-01-14 09:16 发表评论
]]>[Leetcode] Permutation Sequencehttp://www.aygfsteel.com/menglee/archive/2014/01/07/408642.htmlMeng LeeMeng LeeTue, 07 Jan 2014 08:06:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/07/408642.htmlhttp://www.aygfsteel.com/menglee/comments/408642.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/07/408642.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408642.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408642.htmlThe set [1,2,3,…,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation sequence.
Note: Given n will be between 1 and 9 inclusive.

q道题其实有很强的规律可循。首先,n个元素的排列L是n!。在下面的分析中Q让k的范围是0 <= k < n!。(题目代码实际上是1<=k<=n!)
可以看到一个规律,是qnQ个排列中,W一位的元素L(n-1)!一l出现的Q也p如果p = k / (n-1)!Q那么排列的最开始一个元素一定是arr[p]?/div>
q个规律可以cL下去Q在剩余的n-1个元素中逐渐挑选出W二个,W三个,...Q到Wn个元素。程序就l束?/div>
 1 /**
 2  * The set [1,2,3,…,n] contains a total of n! unique permutations.
 3  * 
 4  * By listing and labeling all of the permutations in order, We get the
 5  * following sequence (ie, for n = 3):
 6  * 
 7  * "123" "132" "213" "231" "312" "321" Given n and k, return the kth permutation
 8  * sequence.
 9  * 
10  * Note: Given n will be between 1 and 9 inclusive.
11  * 
12  */
13 
14 public class PermutationSequence {
15     public String getPermutation(int n, int k) {
16         char[] arr = new char[n];
17         int pro = 1;
18         for (int i = 0; i < n; ++i) {
19             arr[i] = (char) ('1' + i);
20             pro *= (i + 1);
21         }
22         k = k - 1;
23         k %= pro;
24         pro /= n;
25         for (int i = 0; i < n - 1; ++i) {
26             int selectI = k / pro;
27             k = k % pro;
28             pro /= (n - i - 1);
29             int temp = arr[selectI + i];
30             for (int j = selectI; j > 0; --j) {
31                 arr[i + j] = arr[i + j - 1];
32             }
33             arr[i] = (char) temp;
34         }
35         return String.valueOf(arr);
36     }
37 }
38 


Meng Lee 2014-01-07 16:06 发表评论
]]>[Leetcode] Lowest Common Ancestor of a Binary Search Tree (BST) && Lowest Common Ancestor of Binary Treehttp://www.aygfsteel.com/menglee/archive/2014/01/06/408544.htmlMeng LeeMeng LeeMon, 06 Jan 2014 01:32:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/06/408544.htmlhttp://www.aygfsteel.com/menglee/comments/408544.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/06/408544.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408544.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408544.html
Lowest Common Ancestor of a Binary Search Tree (BST)
Given a binary search tree (BST), find the lowest common ancestor of two given nodes in the BST.
       _______6______
      /              \
   ___2__          ___8__
  /      \        /      \
  0      _4       7       9
        /  \
        3   5
Using the above tree as an example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6. 
But how about LCA of nodes 2 and 4? Should it be 6 or 2?
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between 
two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a 
node to be a descendant of itself).” Since a node can be a descendant of itself, the LCA of 2 and 
4 should be 2, according to this definition.
Hint:
A top-down walk from the root of the tree is enough.

 1 public class LowestCommonAncestorOfaBinarySearchTree {
 2     public TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
 3         if (root == null || p == null || q == null)
 4             return null;
 5         if (Math.max(p.val, q.val) < root.val)
 6             return LCA(root.left, p, q);
 7         if (Math.min(p.val, q.val) > root.val)
 8             return LCA(root.right, p, q);
 9         return root;
10     }
11 }


Given a binary tree, find the lowest common ancestor of two given nodes in the tree.
 
 
        _______3______
       /              \
    ___5__          ___1__
   /      \        /      \
  6      _2       0       8
         /  \
         7   4
If you are not so sure about the definition of lowest common ancestor (LCA), please refer to my previous 
post: Lowest Common Ancestor of a Binary Search Tree (BST) or the definition of LCA here. Using the tree 
above as an example, the LCA of nodes 5 and 1 is 3. Please note that LCA for nodes 5 and 4 is 5.
 
Hint:
Top-down or bottom-up? Consider both approaches and see which one is more efficient.
 1 public class LowestCommonAncestorOfBinaryTree {
 2     public TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
 3         if (root == null)
 4             return null;
 5         if (root == p || root == q)
 6             return root;
 7         TreeNode left = LCA(root.left, p, q);
 8         TreeNode right = LCA(root.right, p, q);
 9         if (left != null && right != null)
10             return root;
11         return left != null ? left : right;
12     }
13 }


Meng Lee 2014-01-06 09:32 发表评论
]]>[Leetcode] Scramble Stringhttp://www.aygfsteel.com/menglee/archive/2014/01/05/408521.htmlMeng LeeMeng LeeSun, 05 Jan 2014 04:33:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/05/408521.htmlhttp://www.aygfsteel.com/menglee/comments/408521.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/05/408521.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408521.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408521.htmlGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
    great
   /    \
  gr    eat
 / \    /  \
g   r  e   at
           / \
          a   t
To scramble the string, we may choose any non-leaf node and swap its two children.
For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat".
    rgeat
   /    \
  rg    eat
 / \    /  \
r   g  e   at
           / \
          a   t
We say that "rgeat" is a scrambled string of "great".
Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae".
    rgtae
   /    \
  rg    tae
 / \    /  \
r   g  ta  e
       / \
      t   a
We say that "rgtae" is a scrambled string of "great".
Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.

 1 public class ScrambleString {
 2     public boolean isScramble(String s1, String s2) {
 3         if (s1.length() != s2.length())
 4             return false;
 5         if (s1.equals(s2))
 6             return true;
 7 
 8         int[] A = new int[26];
 9         for (int i = 0; i < s1.length(); i++) {
10             ++A[s1.charAt(i) - 'a'];
11         }
12 
13         for (int j = 0; j < s2.length(); j++) {
14             --A[s2.charAt(j) - 'a'];
15         }
16 
17         for (int k = 0; k < 26; k++) {
18             if (A[k] != 0)
19                 return false;
20         }
21 
22         for (int i = 1; i < s1.length(); i++) {
23             boolean result = isScramble(s1.substring(0, i), s2.substring(0, i))
24                     && isScramble(s1.substring(i), s2.substring(i));
25             result = result
26                     || (isScramble(s1.substring(0, i),
27                             s2.substring(s2.length() - i, s2.length())) && isScramble(
28                             s1.substring(i), s2.substring(0, s2.length() - i)));
29             if (result)
30                 return true;
31         }
32         return false;
33     }
34 }


Meng Lee 2014-01-05 12:33 发表评论
]]>
[Leetcode] Largest Rectangle in Histogramhttp://www.aygfsteel.com/menglee/archive/2014/01/05/408520.htmlMeng LeeMeng LeeSun, 05 Jan 2014 04:31:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/05/408520.htmlhttp://www.aygfsteel.com/menglee/comments/408520.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/05/408520.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408520.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408520.htmlGiven n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
The largest rectangle is shown in the shaded area, which has area = 10 unit.
For example,
Given height = [2,1,5,6,2,3],
return 10.

本题需要用栈l护一个高度单调递增的序列下标,如果遇到一个元素比当前栈顶元素高度,那么出栈Qƈ计算当前最大面U。如果栈为空Q需要特D考虑?br />
 1 public class LargestRectangleinHistogram {
 2     public int largestRectangleArea(int[] height) {
 3         Stack<Integer> stack = new Stack<Integer>();
 4         int i = 0;
 5         int maxArea = 0;
 6         int[] h = new int[height.length + 1];
 7         h = Arrays.copyOf(height, height.length + 1);
 8         while (i < h.length) {
 9             if (stack.isEmpty() || h[stack.peek()] <= h[i]) {
10                 stack.push(i++);
11             } else {
12                 int t = stack.pop();
13                 maxArea = Math.max(maxArea, h[t] * (stack.isEmpty() ? i : i - stack.peek() - 1));
14             }
15         }
16         return maxArea;
17     }
18 }


Meng Lee 2014-01-05 12:31 发表评论
]]>
[Leetcode] Binary Tree Inorder Traversalhttp://www.aygfsteel.com/menglee/archive/2014/01/04/408477.htmlMeng LeeMeng LeeSat, 04 Jan 2014 03:17:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/04/408477.htmlhttp://www.aygfsteel.com/menglee/comments/408477.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/04/408477.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408477.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408477.htmlGiven a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
   1
    \
     2
    /
   3
return [1,3,2].
Note: Recursive solution is trivial, could you do it iteratively?

切记p节点初始时指向root.left。代码如下:
 1 public class BinaryTreeInorderTraversal {
 2     public ArrayList<Integer> inorderTraversal(TreeNode root) {
 3         ArrayList<Integer> inOrder = new ArrayList<Integer>();
 4         if (root == null)
 5             return inOrder;
 6         Stack<TreeNode> s = new Stack<TreeNode>();
 7         s.add(root);
 8         TreeNode p = root.left;
 9         while (!s.empty()) {
10             while (p != null) {
11                 s.add(p);
12                 p = p.left;
13             }
14             TreeNode n = s.pop();
15             inOrder.add(n.val);
16             p = n.right;
17             if (p != null) {
18                 s.add(p);
19                 p = p.left;
20             }
21         }
22         return inOrder;
23     }
24 }


Meng Lee 2014-01-04 11:17 发表评论
]]>
[Leetcode] Subsets IIhttp://www.aygfsteel.com/menglee/archive/2014/01/03/408444.htmlMeng LeeMeng LeeFri, 03 Jan 2014 08:40:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/03/408444.htmlhttp://www.aygfsteel.com/menglee/comments/408444.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/03/408444.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408444.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408444.htmlGiven a collection of integers that might contain duplicates, 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 example,
If S = [1,2,2], a solution is:
[
  [2],
  [1],
  [1,2,2],
  [2,2],
  [1,2],
  []
]

׃元素中可能存在重复,因此较之于Subset的实玎ͼ需要加一些判断。如果碰C重复元素Q只需要在上一ơP代新增的子集的基上再q行q代卛_。实C码如下:
 1 public class SubsetsII {
 2     public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) {
 3         ArrayList<ArrayList<Integer>> ret = new ArrayList<ArrayList<Integer>>();
 4         ArrayList<ArrayList<Integer>> lastLevel = null;
 5         ret.add(new ArrayList<Integer>());
 6         Arrays.sort(num);
 7         for (int i = 0; i < num.length; i++) {
 8             ArrayList<ArrayList<Integer>> tmp = new ArrayList<ArrayList<Integer>>();
 9             ArrayList<ArrayList<Integer>> prev = i == 0 || num[i] != num[i - 1] ? ret : lastLevel;
10             for (ArrayList<Integer> s : prev) {
11                 ArrayList<Integer> newSet = new ArrayList<Integer>(s);
12                 newSet.add(num[i]);
13                 tmp.add(newSet);
14             }
15             ret.addAll(tmp);
16             lastLevel = tmp;
17         }
18         return ret;
19     }
20 }


Meng Lee 2014-01-03 16:40 发表评论
]]>
[Leetcode] Word Ladder IIhttp://www.aygfsteel.com/menglee/archive/2014/01/02/408381.htmlMeng LeeMeng LeeThu, 02 Jan 2014 05:59:00 GMThttp://www.aygfsteel.com/menglee/archive/2014/01/02/408381.htmlhttp://www.aygfsteel.com/menglee/comments/408381.htmlhttp://www.aygfsteel.com/menglee/archive/2014/01/02/408381.html#Feedback0http://www.aygfsteel.com/menglee/comments/commentRss/408381.htmlhttp://www.aygfsteel.com/menglee/services/trackbacks/408381.htmlGiven two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:
Only one letter can be changed at a time
Each intermediate word must exist in the dictionary
For example,
Given:
start = "hit"
end = "cog"
dict = ["hot","dot","dog","lot","log"]
Return
  [
    ["hit","hot","dot","dog","cog"],
    ["hit","hot","lot","log","cog"]
  ]
Note:
All words have the same length.
All words contain only lowercase alphabetic characters.

q个题目应该是leetcode上比较难的题目了。刚开始我采用了和Word Ladder怼的做法,只是用ArrayList记录了当前变换\径,在小数据的情况下可以AcceptQ但是大数据时。究其原因,是由于ؓ每个当前节点记录变换路径的时候,需要复制之前的ArrayListQ这个时间开销较大?br />其实Q我们可以采用一个Map<String, HashSet<String>>l构Q记录字典单词的每一个前驱,q样我们可以从end反向遍历Q构造出转换路径?br />同时Q我利用了两个ArrayListQ交替记录上一层和下一层的节点Q如果下一层节点ؓI,则不存在路径Q立卌回。如果下一层中出现了endQ证明找C所有的最短\径,停止搜烦开始构造\径。实C码如下:
 1 public class WordLadderII {
 2     private void GeneratePath(Map<String, ArrayList<String>> prevMap,
 3             ArrayList<String> path, String word,
 4             ArrayList<ArrayList<String>> ret) {
 5         if (prevMap.get(word).size() == 0) {
 6             path.add(0, word);
 7             ArrayList<String> curPath = new ArrayList<String>(path);
 8             ret.add(curPath);
 9             path.remove(0);
10             return;
11         }
12 
13         path.add(0, word);
14         for (String pt : prevMap.get(word)) {
15             GeneratePath(prevMap, path, pt, ret);
16         }
17         path.remove(0);
18     }
19 
20     public ArrayList<ArrayList<String>> findLadders(String start, String end,
21             HashSet<String> dict) {
22         ArrayList<ArrayList<String>> ret = new ArrayList<ArrayList<String>>();
23         Map<String, ArrayList<String>> prevMap = new HashMap<String, ArrayList<String>>();
24         dict.add(start);
25         dict.add(end);
26         for (String d : dict) {
27             prevMap.put(d, new ArrayList<String>());
28         }
29         ArrayList<HashSet<String>> candidates = new ArrayList<HashSet<String>>();
30         candidates.add(new HashSet<String>());
31         candidates.add(new HashSet<String>());
32         int current = 0;
33         int previous = 1;
34         candidates.get(current).add(start);
35         while (true) {
36             current = current == 0 ? 1 : 0;
37             previous = previous == 0 ? 1 : 0;
38             for (String d : candidates.get(previous)) {
39                 dict.remove(d);
40             }
41             candidates.get(current).clear();
42             for (String wd : candidates.get(previous)) {
43                 for (int pos = 0; pos < wd.length(); ++pos) {
44                     StringBuffer word = new StringBuffer(wd);
45                     for (int i = 'a'; i <= 'z'; ++i) {
46                         if (wd.charAt(pos) == i) {
47                             continue;
48                         }
49 
50                         word.setCharAt(pos, (char) i);
51 
52                         if (dict.contains(word.toString())) {
53                             prevMap.get(word.toString()).add(wd);
54                             candidates.get(current).add(word.toString());
55                         }
56                     }
57                 }
58             }
59 
60             if (candidates.get(current).size() == 0) {
61                 return ret;
62             }
63             if (candidates.get(current).contains(end)) {
64                 break;
65             }
66         }
67 
68         ArrayList<String> path = new ArrayList<String>();
69         GeneratePath(prevMap, path, end, ret);
70 
71         return ret;
72     }
73 }


Meng Lee 2014-01-02 13:59 发表评论
]]>
վ֩ģ壺 | | ۶| | ԭ| | | | ͬ| | | | ʢ| | | | | ׿| | ͨ| Ϫ| Ƽ| | | ˮ| ζ| ո| | | ¡| | ̨| | Ұ| | ɽ| | | | | |