问题 缓存 Array.length 是老生常谈的小优化. // 不缓存 for (var i = 0; i < arr.length; i++) { ... } // 缓存 var len = arr.length; for (var i = 0; i < len; i++) { ... } // 或者 for (var i = 0, len = arr.length; i < len; i++) { ... } 但以前写过 Java 的笔者一直对这种破碎的写法感到不适,也对这种写法的…
Learn this from stackflow. public class test { public static void main(String[] args) throws IOException { int [] a={1,2,3,4,4,4,5,4,4}; int r=GetMajorElement(a); System.out.println(r); } //check the element in the array occurs more than half of the…
写在前面 在项目中,有客户反应无法正常加载组织结构树,弄了一个测试的程序,在日志中查看到如下信息: Error in deserializing body of reply message for operation 'GetDepartMentList'. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing…
/* bzoj 2763 SPFA小优化 循环队列+SLF 顺面改掉自己之前手打qeueu的坏毛病*/ #include<iostream> #include<cstring> #include<cstdio> #define mk make pair #define maxn 2000010 #define N 2000000 using namespace std; int n,m,k,s,t,num,hea[maxn],dis[maxn],c[maxn]; int…
I found that both the Array Object and Array.prototype have the length property. I am confused on using the Array.length property. How do you use it? Answer: Array is a constructor function. All functions have a length property that returns the numbe…
Developer deals with arrays every day. Being a collection, an important property to query is the number of items: Array.prototype.length. In JavaScript the length does not always indicate the number of existing elements (for sparse arrays) and modify…
[MySQL5.6] 最近对group commit的小优化 http://www.tuicool.com/articles/rEZr2q 最近花了一些时间在做MySQL Group Commit的优化,关于Group commit的原理,这里不再赘述,有兴趣的可以翻阅我之前的博客 http://mysqllover.com/?p=581,这里简单描述下两点优化,主要基于MySQL5.6.16 1.优化binlog_order_commits=0并且sync_binlog>0时的性能  我们知道…
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2, then one 1" or 1211. Given an…
标签:闲扯 SPFA的小优化 1. 向队尾加入元素时,如果它比对首还优,就把把它直接和队首交换. 拿一个双端队列来实现 (手写 , head ,tail   STLdeque亲测及其慢) 这个小优化其实有点用  被卡成90分时可以试试 =.= if(dis[head]>dis[tail])swap(q[head],q[tail]); 2.求S到T的最短路时 ,如果当前点比dis[T]还弱, 就不要它了 ~…
1.Math.floor(Math.random() * array.length) 返回长度内的索引 eg: changeLimit () { function getArrayItems(arr, num) { const temp_array = []; for(let index in arr) { temp_array.push(arr[index]); } const return_array = []; for (let i = 0; i<num; i++) { if(temp_a…