We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 834c26e commit 673b725Copy full SHA for 673b725
942-di-string-match.js
@@ -22,6 +22,18 @@ const diStringMatch = function(S) {
22
23
// another
24
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
37
/**
38
* @param {string} s
39
* @return {number[]}
0 commit comments