/**
* @param {number} n
* @return {string[]}
*/
var generateParenthesis = function(n) {
let str = 1.0.toFixed(n).substr(2).replace(/0/g, '(')
let result = []
//console.log(str, _case)
let num = n //剩下的
var times = 0
// 递归index,循环num
function insert(_case, index, num) {
console.log('index', index)
num = num > index+1 ? index+1 : num
// console.log( _case ,'_case')
times++
if(times>100){
return
}
if(num == 0){
_case = _case.concat([""])
}
for (var i = 0; i < n; i++) {
// console.log(i,'I')
if (num == 0) {
_case = _case.concat([""])
} else {
_case = _case.concat([str.substr(0, i)])
}
}
if (index <= 0) {
result.push(_case)
}
}
insert([], n-1, num)
return result
}
try {
console.log(generateParenthesis(5))
} catch(e) {
console.log(e)
}
console