添加(二叉树中递归带着回溯.md):增加相同的树typescript版本

This commit is contained in:
Steve2020
2022-02-08 10:23:59 +08:00
parent 04fa7afdfa
commit 47818c9478

View File

@ -515,6 +515,29 @@ var binaryTreePaths = function(root) {
}; };
``` ```
TypeScript
> 相同的树
```typescript
function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean {
if (p === null && q === null) return true;
if (p === null || q === null) return false;
if (p.val !== q.val) return false;
let bool1: boolean, bool2: boolean;
bool1 = isSameTree(p.left, q.left);
bool2 = isSameTree(p.right, q.right);
return bool1 && bool2;
};
```
> 二叉树的不同路径
```typescript
```
----------------------- -----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div> <div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>