Skip to content

Instantly share code, notes, and snippets.

@blackmiaool
Last active June 11, 2017 05:37
Show Gist options
  • Save blackmiaool/16b0d71a9ed704ec28a34e7bc1141f63 to your computer and use it in GitHub Desktop.
Save blackmiaool/16b0d71a9ed704ec28a34e7bc1141f63 to your computer and use it in GitHub Desktop.
leetcode tools
const A=(function (){
const cache={};
return function(num,base){
const key=num+'-'+base;
if(cache[key]){
return cache[key];
}
let ret=1;
for(var i=0;i<num;i++){
ret*=base-i;
}
cache[key]=ret;
return ret;
}
})();
const C=(function (){
const cache={};
return function(num,base){
const key=num+'-'+base;
if(cache[key]){
return cache[key];
}
let ret=A(num,base);
for(var i=2;i<=num;i++){
ret/=i;
}
cache[key]=ret;
return ret;
}
})();
const map={};
const farr=[];
nums.forEach(function(v,i){
if(!map[v]){
map[v]=0;
farr.push(v);
}
map[v]++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment