2014-01-12 W.Y.
在学习排序算法的时候,经常要用到随机数组,于是就写了一个生成随机数组的方法。算法来自网络,只是修改成了 JavaScript 版本。 基本原理是洗牌算法,首先从所有元素中随机选取一个与第一个元素进行交换,然后在第二个之后选择一个元素与第二个交换,直到最后一个元素。这样能确保每个元素在每个位置的概率都是1/n。 具体代码如下: javascript /** * * 生成从 1 到 length 之间的随机数组 * * @length 随机数组的长度,如果未传递该参数,那么 length 为默认值 9 * */ function randomArray(length) { var i, inde 继续阅读 »
2016-02-05 ruki
New features Add automaticlly check libc interfaces Support custom allocator Add trace for allocator in the debug mode Add static_pool module Add stream interfaces for reading all data to string Add adler32 hash algorithm Add tb_memmem interface Add regex module with pcre, pcre2 or posix regex Changes Optimize stre 继续阅读 »
2018-04-03 Alex Sun
1. 风格迁移 2. 算法 具体可以参考论文 A Neural Algorithm of Artistic Style。 继续阅读 »
2015-12-13 MoreFreeze
I have trained my algorithm on leetcode a period of time. Today, I will explain my solution about Minimum Height Trees. My solution beat ~95% against others but it is hard to explain what is I do. Please allow me to introduce the solution from easy to hard. If you only need the last solution, jump to 继续阅读 »
2016-09-28 demon7452
策略模式-Strategy Pattern GitHub源码 定义 The Strategy Pattern defines a family of algorithms(演算法;运算法则;),encapsulates( 总结; 扼要概括; ) each one,and makes them interchangeable(可交换的;可交替的;).Strategy lets the algorithm vary independently from clients that use it. 继续阅读 »
2016-06-16 YongHao Hu
C++
231. Power of Two Question Given an integer, write a function to determine if it is a power of two. Solution Approach #1 (count the number of 1) [Accepted] Algorithm Integer is a power of two means only one bit of n is '1', for example, 100 is 2^2=4 while 110 is 2^2+2^1=6. 继续阅读 »