Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lcci/17.12.BiNode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ func convertBiNode(root *TreeNode) *TreeNode {
}
```

```js
const convertBiNode = root => {
const dfs = root => {
if (!root) {
return;
}
dfs(root.left);
prev.right = root;
root.left = null;
prev = root;
dfs(root.right);
};
const dummy = new TreeNode(0);
let prev = dummy;
dfs(root);
return dummy.right;
};
```

<!-- tabs:end -->

<!-- end -->
19 changes: 19 additions & 0 deletions lcci/17.12.BiNode/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ func convertBiNode(root *TreeNode) *TreeNode {
}
```

```js
const convertBiNode = root => {
const dfs = root => {
if (!root) {
return;
}
dfs(root.left);
prev.right = root;
root.left = null;
prev = root;
dfs(root.right);
};
const dummy = new TreeNode(0);
let prev = dummy;
dfs(root);
return dummy.right;
};
```

<!-- tabs:end -->

<!-- end -->
16 changes: 16 additions & 0 deletions lcci/17.12.BiNode/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const convertBiNode = root => {
const dfs = root => {
if (!root) {
return;
}
dfs(root.left);
prev.right = root;
root.left = null;
prev = root;
dfs(root.right);
};
const dummy = new TreeNode(0);
let prev = dummy;
dfs(root);
return dummy.right;
};