Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42fb596
+linked-list.md +reverse-linked-list
Igneaalis May 13, 2020
080e833
Changed variables' name, added hyperlinks (anchors)
Igneaalis May 22, 2020
0d5a662
Improved [Reverse linked list]
Igneaalis May 22, 2020
57b1910
Added LEETCODE middle-of-the-linked-list solution.
Igneaalis Jun 1, 2020
303c7ae
Added LEETCODE palindrome-linked-list solution.
Igneaalis Jun 1, 2020
cbc585f
Added LEETCODE merge-two-sorted-lists solution.
Igneaalis Jun 1, 2020
07c4497
Added LEETCODE Merge Two Sorted Lists (iterative) solution.
Igneaalis Jun 1, 2020
5d394cc
Added a forgotten link for an iterative solution.
Igneaalis Jun 1, 2020
f6c5605
Added LEETCODE "binary-tree-inorder-traversal" solution.
Igneaalis Jun 1, 2020
4101f7e
Added recursive and iterative,stack LEETCODE "binary-tree-inorder-tra…
Igneaalis Jun 2, 2020
164fd7e
Removed an extra line from recursive solution.
Igneaalis Jun 2, 2020
bee6f14
Removed an extra line from recursive solution (another).
Igneaalis Jun 2, 2020
07205fc
Added LEETCODE "symmetric-tree" solution with euler path.
Igneaalis Jun 3, 2020
0756cfd
Added LEETCODE "maximum-depth-of-binary-tree" solution.
Igneaalis Jun 3, 2020
9b155a3
Added LEETCODE "same-tree" recursive solution.
Igneaalis Jun 3, 2020
9f4cb34
Added LEETCODE "maximum-depth-of-binary-tree" recursive solution.
Igneaalis Jun 3, 2020
e732f70
Added LEETCODE "same-tree" recursive solution.
Igneaalis Jun 3, 2020
c6f6e52
Added LEETCODE "invert-binary-tree" recursive solution.
Igneaalis Jun 3, 2020
c313d6f
Added LEETCODE "path-sum" recursive solution.
Igneaalis Jun 3, 2020
06a7d96
Added LEETCODE "binary-tree-level-order-traversal" recursive solution.
Igneaalis Jun 3, 2020
3a1f0bd
Added LEETCODE "subtree-of-another-tree" recursive solution.
Igneaalis Jun 3, 2020
d0be9f6
Added LEETCODE "kth-smallest-element-in-a-bst" recursive solution.
Igneaalis Jun 4, 2020
a7058f5
Added LEETCODE "validate-binary-search-tree" recursive solution.
Igneaalis Jun 4, 2020
ecea567
Added LEETCODE "binary-search-tree-iterator" solution.
Igneaalis Jun 4, 2020
56f3a10
Changed method name.
Igneaalis Jun 4, 2020
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
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

55 changes: 55 additions & 0 deletions tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Binary tree

+ [Binary Search Tree Iterator](#binary-search-tree-iterator)

## Binary Search Tree Iterator

https://leetcode.com/problems/binary-search-tree-iterator/

```python
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class BSTIterator(object):

def traverse(self, node):
"""
:type node: TreeNode
"""
while node:
self.inorderlist.append(node)
node = node.left

def __init__(self, root):
"""
:type root: TreeNode
"""
self.root = root
self.inorderlist = []
self.traverse(root)

def next(self):
"""
@return the next smallest number
:rtype: int
"""
node = self.inorderlist.pop()
self.traverse(node.right)
return node.val

def hasNext(self):
"""
@return whether we have a next smallest number
:rtype: bool
"""
return len(self.inorderlist) != 0

# Your BSTIterator object will be instantiated and called as such:
# obj = BSTIterator(root)
# param_1 = obj.next()
# param_2 = obj.hasNext()

```