Skip to content

Commit 673b725

Browse files
authored
Update 942-di-string-match.js
1 parent 834c26e commit 673b725

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

942-di-string-match.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ const diStringMatch = function(S) {
2222

2323
// another
2424

25+
/*
26+
27+
it is greedy and one pass !!
28+
so every time when we meet an I, we need to keep in mind that we may meet another I later,
29+
so the safest way is use the smallest number available. same idea when we meet D,
30+
so in order to keep us safe, we always take largest one available, until we traverse the whole string.
31+
And since the available numbers are sorted(from 0 to S.length()),
32+
so we can set two pointers one starts from the head(smallest number),
33+
another from the ends(largest number), then we begin to fill the res array.
34+
35+
*/
36+
2537
/**
2638
* @param {string} s
2739
* @return {number[]}

0 commit comments

Comments
 (0)