摘要: //n个骰子的和,组成数字m的可能 function f(n,m) { if(n==1){ return 1; } var len=m-n; var sum=0; while (len>=0){ len-- //当前骰子和剩余骰子不能大于7 if(m-n+1-len<7&&n-1+len<... 阅读全文
posted @ 2018-03-16 14:54 无工时代 阅读(530) 评论(0) 推荐(0)
摘要: 之前面试的时候,面试官问我的一个题目, 问:一个人在w*h的地图上走,每次走一步,先向左走到头,然后向下走,然后向上走,然后向左走,不能重复,求n步所在的位置 如下: 它会依次输出1-64, 阅读全文
posted @ 2017-12-19 15:40 无工时代 阅读(509) 评论(0) 推荐(0)
摘要: class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): try: self.impl = _GetchWindows() except ImportEr... 阅读全文
posted @ 2017-12-06 19:33 无工时代 阅读(1373) 评论(0) 推荐(0)
摘要: //获取数组中两个相加等于0的一对数字,比如[ [ -10, 10 ], [ -5, 5 ] ] var arr=[-5,10,1,-10,3,4,5,9] //对数组进行排序 arr.sort(function(num1,num2){ if(num1>num2)return 1; if(num1num){ s2-- } i... 阅读全文
posted @ 2017-06-15 09:24 无工时代 阅读(805) 评论(0) 推荐(0)
摘要: //矩阵运算的函数 ;(function(global){ global.Matrix = { //生成对角矩阵,非零元素都为1 eye : function( n ){ var result = []; var arr; for ( var i = 0; i 0 ) { ... 阅读全文
posted @ 2017-03-06 17:39 无工时代 阅读(521) 评论(0) 推荐(0)
摘要: function getInfo(html){ //去掉注释 html=html.replace(//g,"") var arrP=[] var reg=/]*>|>)[\d\D]*?/gi html.replace(reg,function(m){ if(/^/gi.test(m)){ m= m.replace(... 阅读全文
posted @ 2017-03-06 17:37 无工时代 阅读(237) 评论(0) 推荐(0)
摘要: /* * config * caoke */ 'use strict'; //You can't use merge in util.js function merge(source, target){ if(typeof source === 'object' && typeof target === 'object'){ for(var key in targ... 阅读全文
posted @ 2017-01-10 15:29 无工时代 阅读(229) 评论(0) 推荐(0)
摘要: /* * config * caoke */ 'use strict'; Object.extend=function(props){ //继承父类 var prototype=Object.create(this.prototype) //初始化函数ctor var _Class=function(){ if(arguments.leng... 阅读全文
posted @ 2017-01-10 15:17 无工时代 阅读(212) 评论(0) 推荐(0)
摘要: var glob = require("glob") // options is optional var fs=require("fs") glob("**", function (er, files) { files.forEach(function(file){ var stat=fs.lstatSync(file) if(!stat.isDi... 阅读全文
posted @ 2016-11-16 19:58 无工时代 阅读(556) 评论(0) 推荐(0)
摘要: var config={ //不想访问的东西,节约流量 "404":[ "http://qidian.qpic.cn/qdbimg" ], //奇数为需要下载的,偶数为不需要下载的 needLoad:[ //匹配需要下载的 [ "/*.js", "/*.css"... 阅读全文
posted @ 2016-11-10 20:46 无工时代 阅读(456) 评论(0) 推荐(0)