Skip to content

Commit

Permalink
feature: 94 solution added
Browse files Browse the repository at this point in the history
  • Loading branch information
royIdoodle committed Aug 29, 2019
1 parent be1237b commit ca3a44d
Showing 1 changed file with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@

## 解题方案

> 思路 1
> 思路 1 迭代
> **- 时间复杂度: O(3N)**
>
> **- 空间复杂度: O(N)**
**递归**

> 执行用时 :**64 ms**, 在所有 JavaScript 提交中击败了**97.85%**的用户
>
> 内存消耗 :**33.7 MB**, 在所有 JavaScript 提交中击败了**34.70%**的用户
Expand Down Expand Up @@ -67,3 +65,42 @@ const inorderTraversal = node => {
```



> 思路 2 迭代
>
> - 时间复杂度: O(N²)
> - 空间复杂度: O(N²)
>执行用时 :**76 ms**, 在所有 JavaScript 提交中击败了**69.05%**的用户
>
>内存消耗 :**33.7 MB**, 在所有 JavaScript 提交中击败了**36.57%**的用户
```javascript
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
const inorderTraversal = (node) => {
const valList = []
const stack = []
while (node || stack.length) {
if (node) {
stack.push(node)
node = node.left
} else {
node = stack.pop()
valList.push(node.val)
node = node.right
}
}
return valList
};
```

0 comments on commit ca3a44d

Please sign in to comment.