Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc91ec7

Browse filesBrowse files
author
Kohei Asai
authored
Refactor data structures (#114)
1 parent be8848f commit bc91ec7
Copy full SHA for bc91ec7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

44 files changed

+260
-265
lines changed

‎solutions/binaryTreeInorderTraversal.test.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreeInorderTraversal.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import inorderTraversal from "./binaryTreeInorderTraversal";
33

44
describe("94. Binary Tree Inorder Traversal", () => {

‎solutions/binaryTreeInorderTraversal.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreeInorderTraversal.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 94. Binary Tree Inorder Traversal
44
// https://leetcode.com/problems/binary-tree-inorder-traversal/
5-
export default function inorderTraversal<T>(root: TreeNode<T> | null): T[] {
5+
export default function inorderTraversal<T>(
6+
root: BinaryTreeNode<T> | null
7+
): T[] {
68
const history: T[] = [];
79

8-
function traverse(node: TreeNode<T> | null): void {
10+
function traverse(node: BinaryTreeNode<T> | null): void {
911
if (node === null) return;
1012

1113
traverse(node.left);

‎solutions/binaryTreeLevelOrderTraversal.test.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreeLevelOrderTraversal.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import levelOrder from "./binaryTreeLevelOrderTraversal";
33

44
describe("102. Binary Tree Level Order Traversal", () => {

‎solutions/binaryTreeLevelOrderTraversal.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreeLevelOrderTraversal.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 102. Binary Tree Level Order Traversal
44
// https://leetcode.com/problems/binary-tree-level-order-traversal/
5-
export default function levelOrder<T>(root: TreeNode<T> | null): T[][] {
5+
export default function levelOrder<T>(root: BinaryTreeNode<T> | null): T[][] {
66
const valuesEachLevel: T[][] = [];
77

8-
function traverse(node: TreeNode<T> | null, level: number) {
8+
function traverse(node: BinaryTreeNode<T> | null, level: number) {
99
if (node === null) return;
1010

1111
if (valuesEachLevel[level]) {

‎solutions/binaryTreePostorderTraversal.test.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreePostorderTraversal.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import postorderTraversal from "./binaryTreePostorderTraversal";
33

44
describe("145. Binary Tree Postorder Traversal", () => {

‎solutions/binaryTreePostorderTraversal.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreePostorderTraversal.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 145. Binary Tree Postorder Traversal
44
// https://leetcode.com/problems/binary-tree-postorder-traversal/
5-
export default function postorderTraversal<T>(root: TreeNode<T> | null): T[] {
5+
export default function postorderTraversal<T>(
6+
root: BinaryTreeNode<T> | null
7+
): T[] {
68
const history: T[] = [];
79

8-
function traverse(node: TreeNode<T> | null): void {
10+
function traverse(node: BinaryTreeNode<T> | null): void {
911
if (node === null) return;
1012

1113
traverse(node.left);

‎solutions/binaryTreePreorderTraversal.test.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreePreorderTraversal.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import preorderTraversal from "./binaryTreePreorderTraversal";
33

44
describe("144. Binary Tree Preorder Traversal", () => {

‎solutions/binaryTreePreorderTraversal.ts

Copy file name to clipboardExpand all lines: solutions/binaryTreePreorderTraversal.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 144. Binary Tree Preorder Traversal
44
// https://leetcode.com/problems/binary-tree-preorder-traversal/
5-
export default function preorderTraversal<T>(root: TreeNode<T> | null): T[] {
5+
export default function preorderTraversal<T>(
6+
root: BinaryTreeNode<T> | null
7+
): T[] {
68
const history: T[] = [];
79

8-
function traverse(node: TreeNode<T> | null): void {
10+
function traverse(node: BinaryTreeNode<T> | null): void {
911
if (node === null) return;
1012

1113
history.push(node.val);

‎solutions/countCompleteTreeNodes.test.ts

Copy file name to clipboardExpand all lines: solutions/countCompleteTreeNodes.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import countNodes from "./countCompleteTreeNodes";
33

44
describe("222. Count Complete Tree Nodes", () => {

‎solutions/countCompleteTreeNodes.ts

Copy file name to clipboardExpand all lines: solutions/countCompleteTreeNodes.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 222. Count Complete Tree Nodes
44
// https://leetcode.com/problems/count-complete-tree-nodes/
5-
function countNodes(root: TreeNode<number> | null): number {
5+
function countNodes(root: BinaryTreeNode<number> | null): number {
66
if (!root) return 0;
77

88
const leftHeight = calculateHeight(root.left);
@@ -17,7 +17,7 @@ function countNodes(root: TreeNode<number> | null): number {
1717
2 ** rightHeight + countNodes(root.left);
1818
}
1919

20-
function calculateHeight(root: TreeNode<number> | null): number {
20+
function calculateHeight(root: BinaryTreeNode<number> | null): number {
2121
return root ? 1 + calculateHeight(root.left) : 0;
2222
}
2323

‎solutions/countUnivalueSubtrees.test.ts

Copy file name to clipboardExpand all lines: solutions/countUnivalueSubtrees.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import countUnivalSubtrees from "./countUnivalueSubtrees";
33

44
describe("250. Count Univalue Subtrees", () => {

‎solutions/countUnivalueSubtrees.ts

Copy file name to clipboardExpand all lines: solutions/countUnivalueSubtrees.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 250. Count Univalue Subtrees
44
// https://leetcode.com/problems/count-univalue-subtrees/
55
export default function countUnivalSubtrees(
6-
root: TreeNode<number> | null
6+
root: BinaryTreeNode<number> | null
77
): number {
8-
function traverse(node: TreeNode<number> | null): [number, number | null] {
8+
function traverse(
9+
node: BinaryTreeNode<number> | null
10+
): [number, number | null] {
911
if (node === null) return [0, null];
1012

1113
let [leftCount, leftValue] = traverse(node.left);

‎solutions/diameterOfBinaryTree.test.ts

Copy file name to clipboardExpand all lines: solutions/diameterOfBinaryTree.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import diameterOfBinaryTree from "./diameterOfBinaryTree";
33

44
describe("543. Diameter of Binary Tree", () => {

‎solutions/diameterOfBinaryTree.ts

Copy file name to clipboardExpand all lines: solutions/diameterOfBinaryTree.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 543. Diameter of Binary Tree
44
// https://leetcode.com/problems/diameter-of-binary-tree/
55
export default function diameterOfBinaryTree<T>(
6-
node: TreeNode<T> | null
6+
node: BinaryTreeNode<T> | null
77
): number {
8-
function getHeightAndDiameter(node: TreeNode<T> | null): [number, number] {
8+
function getHeightAndDiameter(
9+
node: BinaryTreeNode<T> | null
10+
): [number, number] {
911
if (node === null) return [-1, -1];
1012

1113
const [leftHeight, leftDiameter] = getHeightAndDiameter(node.left);

‎solutions/linkedListCycle.test.ts

Copy file name to clipboardExpand all lines: solutions/linkedListCycle.test.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createListNode, ListNode } from "../utilities/ListNode";
1+
import { createSinglyLinkedListNode } from "../testUtilities/LinkedList";
2+
import { SinglyLinkedListNode } from "../types/LinkedList";
23
import hasCycle from "./linkedListCycle";
34

45
describe("141. Linked List Cycle", () => {
@@ -10,10 +11,10 @@ describe("141. Linked List Cycle", () => {
1011

1112
for (const [[values, cycleStart], expected] of TEST_CASES) {
1213
it(`returns ${expected} when called with [${values}] (cycle starts from ${cycleStart})`, () => {
13-
const head = createListNode(values);
14+
const head = createSinglyLinkedListNode(values);
1415

1516
let node = head;
16-
let cycleStartNode: ListNode<number> | null = null;
17+
let cycleStartNode: SinglyLinkedListNode<number> | null = null;
1718

1819
for (const i of values.keys()) {
1920
if (i === cycleStart) {

‎solutions/linkedListCycle.ts

Copy file name to clipboardExpand all lines: solutions/linkedListCycle.ts
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { ListNode } from "../utilities/ListNode";
1+
import { SinglyLinkedListNode } from "../types/LinkedList";
22

33
// 141. Linked List Cycle
44
// https://leetcode.com/problems/linked-list-cycle/
5-
export default function hasCycle<T>(head: ListNode<T> | null): boolean {
5+
export default function hasCycle<T>(
6+
head: SinglyLinkedListNode<T> | null
7+
): boolean {
68
function traverse(
7-
previous: ListNode<T> | null,
8-
node: ListNode<T> | null
9+
previous: SinglyLinkedListNode<T> | null,
10+
node: SinglyLinkedListNode<T> | null
911
): boolean {
1012
if (node === null) return false;
1113
if (node === head && previous !== null) return true;

‎solutions/maximumDepthOfBinaryTree.test.ts

Copy file name to clipboardExpand all lines: solutions/maximumDepthOfBinaryTree.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import maxDepth from "./maximumDepthOfBinaryTree";
33

44
describe("104. Maximum Depth of Binary Tree", () => {

‎solutions/maximumDepthOfBinaryTree.ts

Copy file name to clipboardExpand all lines: solutions/maximumDepthOfBinaryTree.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 104. Maximum Depth of Binary Tree
44
// https://leetcode.com/problems/maximum-depth-of-binary-tree/
5-
export default function maxDepth<T>(node: TreeNode<T> | null): number {
5+
export default function maxDepth<T>(node: BinaryTreeNode<T> | null): number {
66
return node === null
77
? 0
88
: Math.max(maxDepth(node.left), maxDepth(node.right)) + 1;

‎solutions/mergeTwoLists.test.ts

Copy file name to clipboardExpand all lines: solutions/mergeTwoLists.test.ts
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createListNode } from "../utilities/ListNode";
1+
import { createSinglyLinkedListNode } from "../testUtilities/LinkedList";
22
import mergeTwoLists from "./mergeTwoLists";
33

44
describe("21. Merge Two Sorted Lists", () => {
@@ -10,8 +10,11 @@ describe("21. Merge Two Sorted Lists", () => {
1010
for (const [[list1, list2], expected] of TEST_CASES) {
1111
it(`returns [${expected}] when called with [${list1}] and [${list2}]`, () => {
1212
expect(
13-
mergeTwoLists(createListNode(list1), createListNode(list2))
14-
).toEqual(createListNode(expected));
13+
mergeTwoLists(
14+
createSinglyLinkedListNode(list1),
15+
createSinglyLinkedListNode(list2)
16+
)
17+
).toEqual(createSinglyLinkedListNode(expected));
1518
});
1619
}
1720
});

‎solutions/mergeTwoLists.ts

Copy file name to clipboardExpand all lines: solutions/mergeTwoLists.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { ListNode } from "../utilities/ListNode";
1+
import { SinglyLinkedListNode } from "../types/LinkedList";
22

33
// 21. Merge Two Sorted Lists
44
// https://leetcode.com/problems/merge-two-sorted-lists/
55
function mergeTwoLists<T>(
6-
list1: ListNode<T> | null,
7-
list2: ListNode<T> | null
8-
): ListNode<T> | null {
6+
list1: SinglyLinkedListNode<T> | null,
7+
list2: SinglyLinkedListNode<T> | null
8+
): SinglyLinkedListNode<T> | null {
99
if (!list1) {
1010
return list2;
1111
}

‎solutions/minimumDepthOfBinaryTree.test.ts

Copy file name to clipboardExpand all lines: solutions/minimumDepthOfBinaryTree.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import minDepth from "./minimumDepthOfBinaryTree";
33

44
describe("111. Minimum Depth of Binary Tree", () => {

‎solutions/minimumDepthOfBinaryTree.ts

Copy file name to clipboardExpand all lines: solutions/minimumDepthOfBinaryTree.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 111. Minimum Depth of Binary Tree
44
// https://leetcode.com/problems/minimum-depth-of-binary-tree/
5-
export default function minDepth<T>(node: TreeNode<T> | null) {
6-
const queue: [TreeNode<T> | null, number][] = [[node, 1]];
5+
export default function minDepth<T>(node: BinaryTreeNode<T> | null) {
6+
const queue: [BinaryTreeNode<T> | null, number][] = [[node, 1]];
77

88
while (queue.length > 0) {
99
const [node, depth] = queue.shift()!;

‎solutions/palindromeLinkedList.test.ts

Copy file name to clipboardExpand all lines: solutions/palindromeLinkedList.test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createListNode } from "../utilities/ListNode";
1+
import { createSinglyLinkedListNode } from "../testUtilities/LinkedList";
22
import isPalindrome from "./palindromeLinkedList";
33

44
describe("234. Palindrome Linked List", () => {
@@ -11,7 +11,7 @@ describe("234. Palindrome Linked List", () => {
1111

1212
for (const [values, expected] of TEST_CASES) {
1313
it(`returns ${expected} when called with [${values}]`, () => {
14-
expect(isPalindrome(createListNode(values))).toBe(expected);
14+
expect(isPalindrome(createSinglyLinkedListNode(values))).toBe(expected);
1515
});
1616
}
1717
});

‎solutions/palindromeLinkedList.ts

Copy file name to clipboardExpand all lines: solutions/palindromeLinkedList.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { ListNode } from "../utilities/ListNode";
1+
import { SinglyLinkedListNode } from "../types/LinkedList";
22

33
// 234. Palindrome Linked List
44
// https://leetcode.com/problems/palindrome-linked-list/
5-
export default function isPalindrome<T>(node: ListNode<T> | null): boolean {
5+
export default function isPalindrome<T>(
6+
node: SinglyLinkedListNode<T> | null
7+
): boolean {
68
let left = node;
79

8-
function traverse(right: ListNode<T> | null): boolean {
10+
function traverse(right: SinglyLinkedListNode<T> | null): boolean {
911
if (right === null) return true;
1012

1113
const isNextMightBePalindrome = traverse(right.next);

‎solutions/pathSum.test.ts

Copy file name to clipboardExpand all lines: solutions/pathSum.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import pathSum from "./pathSum";
33

44
describe("112. Path Sum", () => {

‎solutions/pathSum.ts

Copy file name to clipboardExpand all lines: solutions/pathSum.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 112. Path Sum
44
// https://leetcode.com/problems/path-sum/
55
export default function hasPathSum(
6-
root: TreeNode<number> | null,
6+
root: BinaryTreeNode<number> | null,
77
sum: number
88
): boolean {
99
// ⚠️ as following the test cases, we need to return false for hasPathSum(null, 0)

‎solutions/reverseLinkedList.test.ts

Copy file name to clipboardExpand all lines: solutions/reverseLinkedList.test.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createListNode } from "../utilities/ListNode";
1+
import { createSinglyLinkedListNode } from "../testUtilities/LinkedList";
22
import reverseList from "./reverseLinkedList";
33

44
describe("206. Reverse Linked List", () => {
@@ -11,8 +11,8 @@ describe("206. Reverse Linked List", () => {
1111

1212
for (const [values, expected] of TEST_CASES) {
1313
it(`returns [${expected}] when called with [${values}]`, () => {
14-
expect(reverseList(createListNode(values))).toEqual(
15-
createListNode(expected)
14+
expect(reverseList(createSinglyLinkedListNode(values))).toEqual(
15+
createSinglyLinkedListNode(expected)
1616
);
1717
});
1818
}

‎solutions/reverseLinkedList.ts

Copy file name to clipboardExpand all lines: solutions/reverseLinkedList.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { ListNode } from "../utilities/ListNode";
1+
import { SinglyLinkedListNode } from "../types/LinkedList";
22

33
// 206. Reverse Linked List
44
// https://leetcode.com/problems/reverse-linked-list/
5-
function reverseList<T>(head: ListNode<T> | null): ListNode<T> | null {
5+
function reverseList<T>(
6+
head: SinglyLinkedListNode<T> | null
7+
): SinglyLinkedListNode<T> | null {
68
if (head === null || head.next === null) return head;
79

810
// call itself recursively with next node as the new head: [1, 2, 3] -> [2, 3] -> [3]

‎solutions/subtreeOfAnotherTree.test.ts

Copy file name to clipboardExpand all lines: solutions/subtreeOfAnotherTree.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import isSubtree from "./subtreeOfAnotherTree";
33

44
describe("572. Subtree of Another Tree", () => {

‎solutions/subtreeOfAnotherTree.ts

Copy file name to clipboardExpand all lines: solutions/subtreeOfAnotherTree.ts
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { TreeNode } from "../utilities/TreeNode";
1+
import { BinaryTreeNode } from "../types/BinaryTree";
22

33
// 572. Subtree of Another Tree
44
// https://leetcode.com/problems/subtree-of-another-tree/
55
export default function isSubtree<T = number>(
6-
s: TreeNode<T> | null,
7-
t: TreeNode<T> | null
6+
s: BinaryTreeNode<T> | null,
7+
t: BinaryTreeNode<T> | null
88
): boolean {
99
return s === null
1010
? s === t
1111
: isSameTree(s, t) || isSubtree(s.left, t) || isSubtree(s.right, t);
1212
}
1313

14-
function isSameTree<T>(s: TreeNode<T> | null, t: TreeNode<T> | null): boolean {
14+
function isSameTree<T>(
15+
s: BinaryTreeNode<T> | null,
16+
t: BinaryTreeNode<T> | null
17+
): boolean {
1518
if (s === null && t === null) return true;
1619

1720
if (s !== null && t !== null)

‎solutions/symmetricTree.test.ts

Copy file name to clipboardExpand all lines: solutions/symmetricTree.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBinaryTreeNode } from "../utilities/TreeNode";
1+
import { createBinaryTreeNode } from "../testUtilities/BinaryTree";
22
import isSymmetric from "./symmetricTree";
33

44
describe("101. Symmetric Tree", () => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.