Title: #173 - Binary Search Tree Iterator - LeetCode JavaScript Solutions
Open Graph Title: #173 - Binary Search Tree Iterator - LeetCode JavaScript Solutions
X Title: #173 - Binary Search Tree Iterator - LeetCode JavaScript Solutions
Description: Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode...
Open Graph Description: Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode...
X Description: Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/binary-search-tree-iterator
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/binary-search-tree-iterator","name":"#173 - Binary Search Tree Iterator - LeetCode JavaScript Solutions","description":"Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar BSTIterator = function(root) {\n this.stack = [];\n this.root = root;\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.next = function() {\n while (this.root) {\n this.stack.push(this.root);\n this.root = this.root.left;\n }\n this.root = this.stack.pop();\n\n const result = this.root.val;\n this.root = this.root.right;\n return result;\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasNext = function() {\n return this.root || this.stack.length;\n};","keywords":"LeetCode 173, #173 - Binary Search Tree Iterator, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/binary-search-tree-iterator |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/binary-search-tree-iterator/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0173-binary-search-tree-iterator.js |
| Tree | https://leetcodejavascript.com/tags/tree |
| Binary Tree | https://leetcodejavascript.com/tags/binary-tree |
| Stack | https://leetcodejavascript.com/tags/stack |
| Design | https://leetcodejavascript.com/tags/design |
| Binary Search Tree | https://leetcodejavascript.com/tags/binary-search-tree |
| Iterator | https://leetcodejavascript.com/tags/iterator |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow