算法题:
- https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/
解题
function dfs(root,num) {if (!root) {return 0}let sum = 10*num+root.valif (!root.left && !root.right) {return sum} else {return dfs(root.left,sum)+dfs(root.right,sum)}}var sumNumbers = function(root) {return dfs(root,0)};
手写题:
题目:给定只含有a、b 和 c的字符串,请去掉其中的b 和 ac。
removeChars('ab') // 'a'removeChars('abc') // ''removeChars('cabbaabcca') // 'caa'
解题: ```javascript function removeChars(input) { // your code here let str = ‘’ for (let i =0,len=input.length;i<len;i++){ if (input[i] ===’c’) {
if (str[str.length-1] ==='a' && str[str.length-1]) {str = str.slice(0,str.length-1)} else {str=str+input[i]}
} if (input[i] === ‘a’){
str=str+input[i]
} } return str }
```
