https://leetcode.com/problems/merge-sorted-array/ 因为这里要求inplace修改nums1.所以不要新申请一个list。小trick就是twopointers从list末尾开始scan。最后要注意n>m的时候,还要把剩余的nums2加到nums1中http://chaoren.is-programmer.com/posts/42844.html classSolution(object): defmerge(self,nums1,m,nums2,n): """ :typenums1:List[int] :typem:int :type...
典型问题:迷宫问题, 核心:也是搜索树类型的解空间,只不过目标只需要找到其中一个目标解,就可以break了。而不是跟回溯一样遍历整个树的从根节点到叶子节点的path,然后找到一条最佳的path
trick: ifusingpython,wecanswaptwoelementslike\ A[k],A[minimal]=A[minimal],A[k] problem: Anon-emptyzero-indexedarrayAconsistingofNintegersisgiven.Theproductoftriplet(P,Q,R)equatestoA[P]A[Q]A[R](0≤P<Q<R<N). Forexample,arrayAsuchthat: A[0]=-3A[1]=1A[2]=2A[3]=-2A[4]=5A[5]=6containsthefollowi...
https://leetcode.com/problems/permutation-sequence/ 参考:http://bangbingsyb.blogspot.hk/2014/11/leetcode-permutation-sequence.html http://fisherlei.blogspot.hk/2013/04/leetcode-permutation-sequence-solution.html 思路:分别计算第k个permutation的各个字母。 classSolution(object): defgetPermutation(self,n,k): """ :typ...
1.Dirichlet概率分布是概率分布的分布。itssupport是simplex,即Dirichlet概率密度函数的定义域是simplex上的一个点。DirichletDistribution描述了simplex上每个点的概率,如下图所示 Figure1DirichletDistribution(Fromwiki) 2.Dirichlet分布的参数alpha_i表示pesudocounts,即categorydistribution中选中第i个component的次数...