From 7793a6db73f2cb5ff9991e2a2590ab0e13ff766e Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 11 Apr 2025 05:03:34 +0300 Subject: [PATCH] Improved tasks 173, 209 --- .../solution.ts | 34 +++++++++---------- .../solution.test.ts | 6 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts b/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts index 2454b58..077a102 100644 --- a/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts +++ b/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts @@ -2,7 +2,7 @@ // #Data_Structure_II_Day_17_Tree #Programming_Skills_II_Day_16 #Level_2_Day_9_Binary_Search_Tree // #Top_Interview_150_Binary_Tree_General #2025_04_09_Time_6_ms_(98.16%)_Space_69.76_MB_(29.04%) -import { TreeNode } from "../../com_github_leetcode/treenode"; +import { TreeNode } from '../../com_github_leetcode/treenode' /** * Definition for a binary tree node. @@ -18,41 +18,41 @@ import { TreeNode } from "../../com_github_leetcode/treenode"; * } */ class BSTIterator { - private node: TreeNode | null; + private node: TreeNode | null constructor(root: TreeNode | null) { - this.node = root; + this.node = root } next(): number { - let res = -1; + let res = -1 while (this.node !== null) { if (this.node.left !== null) { - let rightMost = this.node.left; + let rightMost = this.node.left while (rightMost.right !== null && rightMost.right !== this.node) { - rightMost = rightMost.right; + rightMost = rightMost.right } if (rightMost.right === null) { - rightMost.right = this.node; - this.node = this.node.left; + rightMost.right = this.node + this.node = this.node.left } else { - rightMost.right = null; - res = this.node.val; - this.node = this.node.right; - return res; + rightMost.right = null + res = this.node.val + this.node = this.node.right + return res } } else { - res = this.node.val; - this.node = this.node.right; - return res; + res = this.node.val + this.node = this.node.right + return res } } - return res; + return res } hasNext(): boolean { - return this.node !== null; + return this.node !== null } } diff --git a/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts b/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts index 24a92d0..5ad38e7 100644 --- a/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts +++ b/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts @@ -3,13 +3,13 @@ import { minSubArrayLen } from 'src/main/ts/g0201_0300/s0209_minimum_size_subarr import { expect, test } from 'vitest' test('minSubArrayLen', () => { - expect(minSubArrayLen(7, [2,3,1,2,4,3])).toEqual(2) + expect(minSubArrayLen(7, [2, 3, 1, 2, 4, 3])).toEqual(2) }) test('minSubArrayLen2', () => { - expect(minSubArrayLen(4, [1,4,4])).toEqual(1) + expect(minSubArrayLen(4, [1, 4, 4])).toEqual(1) }) test('minSubArrayLen3', () => { - expect(minSubArrayLen(11, [1,1,1,1,1,1,1,1])).toEqual(0) + expect(minSubArrayLen(11, [1, 1, 1, 1, 1, 1, 1, 1])).toEqual(0) })