Skip to content

Commit a569aa3

Browse files
committed
added dbg for maxProfit()
1 parent 38795b2 commit a569aa3

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/array/max-profit.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,28 @@ export function maxProfit(prices: number[]): number {
1212

1313
return maxProfit;
1414
}
15+
16+
export function maxProfitDBG(){
17+
18+
const tests = [
19+
{
20+
input: [7, 1, 5, 3, 6, 4],
21+
result: 5 // Купить за 1 и продать за 6
22+
},
23+
{
24+
input: [7, 6, 4, 3, 1],
25+
result: 0 // Прибыль не возможна
26+
}
27+
];
28+
29+
tests.forEach((test, index) => {
30+
const result = maxProfit(test.input);
31+
if (result === test.result) {
32+
console.log(`${index} success`);
33+
} else {
34+
console.log(`${index} fail`);
35+
console.log(`expected ${test.result}`);
36+
console.log(`got ${result}`);
37+
}
38+
});
39+
}

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { majorityElementDBG } from "./array/majority-element";
2+
import { maxProfitDBG } from "./array/max-profit";
3+
import { productExceptSelfDBG } from "./array/product-except-self";
24
import { printTree, TreeNode } from "./bst";
35
import { lowestCommonAncestorDBG } from "./bst/problems/lowest-common-ancestor";
46
import { HitCounterDBG } from "./scratch_structure/hit-counter";
57
import { longestPalindromeDBG } from "./string/longest-palindrome";
68

7-
longestPalindromeDBG()
9+
maxProfitDBG()

0 commit comments

Comments
 (0)