# Leetcode306累加数（递归解决）

·  阅读 43
``````/**
* @param {string} num
* @return {boolean}
*/
let flag = false
var addStrings = function(num1, num2) {
let arr1 = num1.split('').map(item=>{return Number(item)})
let arr2 = num2.split('').map(item=>{return Number(item)})
let jin = 0
let str = ''
while(arr1.length || arr2.length || jin){
let number1 = arr1.pop() || 0
let number2 = arr2.pop() || 0
str =(jin + number2 + number1)%10 + str
jin = Math.floor((jin + number2 + number1)/10)
}
return str

};
function dfs(pre,curr,rest){
if(pre.length >1 && pre[0] === "0"){
return
}
if(curr.length >1 && curr[0] === "0"){
return
}
if(rest === ''){
flag = true
return
}
if(rest.length < total.length){
return
}
let next = rest.substring(0,total.length)
if(next === total){
dfs(curr,next,rest.substring(total.length))
}

}

// i是第一个字符串尾部对应的索引
// j是第二个字符串尾部对应的索引
for(let i=0;i<num.length;i++){
// TODO
// 进一步，限制
// 进一步
// 搞定这个i j的关系
for(let j=i+1;j-i<=num.length -j;j++){
if(num.substring(j+1)){
dfs(num.substring(0,i+1),num.substring(i+1,j+1),num.substring(1+j))
}
}
}
return flag

};