mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-12 05:20:59 +08:00
添加(二叉树中递归带着回溯.md):增加相同的树typescript版本
This commit is contained in:
@ -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>
|
||||||
|
Reference in New Issue
Block a user