标签:正整数 ring tmp tostring push sort size i++ join
var splitN = function f(n){ if(n == 1) return new Array("1"); else if(n == 2)return new Array("1,1","2"); else{ var tmp = new Array(); tmp.push(n); tmp.push((n-1) + ",1"); var arr2 = new Array("1,1","2"); var r = f(n-2); for(var i = 0;i < r.length ; i++){ tmp.push(arr2[0]+"," + r[i]); tmp.push(arr2[1]+"," + r[i]); } //sort each for(var i = 0;i < tmp.length; i++)tmp [i] = tmp[i].toString().split(‘,‘).sort().join(‘,‘); //remove duplicate var tmp2 = new Array(); for(var i = 0;i < tmp.length; i++){if(tmp2.indexOf(tmp[i]) < 0) tmp2.push(tmp[i]);} return tmp2; } } var ret = splitN(6); console.log(ret);
标签:正整数 ring tmp tostring push sort size i++ join
原文地址:http://www.cnblogs.com/yutingliuyl/p/7140521.html