This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nextGreaterElement(nums1, nums2){ | |
const ans = [] | |
// monotonic stack | |
const stack = [] | |
const map = {} | |
nums2.forEach(num => { | |
if (stack.length === 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function fractionToDecimal(numerator, denominator){ | |
if (numerator === 0) { | |
return 0 | |
} | |
let result = "" | |
if (numerator < 0 ^ denominator < 0) { | |
result = "-"; | |
numerator = Math.abs(numerator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function populateNextPointers(root) { | |
// we traverse the tree level by level by using two variables, | |
// left and current | |
// left is always the leftmost element of the current level, | |
// current starts the same as left, but moves right along the level | |
// as soon as current has nowhere to move, we shift level by shifting left down one level, and setting current to the same as left | |
// so the algorithm is | |
// root is left, current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TreeNode } from "./ds_v1/BinaryTree.js"; | |
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } | |
import { TreeNode } from "./ds_v1/BinaryTree.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } | |
import { TreeNode } from "./ds_v1/BinaryTree.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TreeNode } from "./ds_v1/BinaryTree.js"; | |
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } | |
import { TreeNode } from "./ds_v1/BinaryTree.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } | |
import { TreeNode } from "./ds_v1/BinaryTree.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition of a binary tree node | |
// class TreeNode { | |
// constructor(data) { | |
// this.data = data; | |
// this.left = null; | |
// this.right = null; | |
// } | |
// } | |
import { TreeNode } from "./ds_v1/BinaryTree.js"; |
NewerOlder