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 29d9d8c commit 03733abCopy full SHA for 03733ab
2289-steps-to-make-array-non-decreasing.js
@@ -40,3 +40,29 @@ const totalSteps = function(nums) {
40
41
return res
42
};
43
+
44
+// another
45
46
+/**
47
+ * @param {number[]} nums
48
+ * @return {number}
49
+ */
50
+const totalSteps = function(nums) {
51
+ let res = 0
52
+ const stk = []
53
+ for(const e of nums) {
54
+ let steps = 1
55
+ while(stk.length && e >= stk[stk.length - 1][0]) {
56
+ const tmp = stk.pop()
57
+ steps = Math.max(tmp[1] + 1, steps)
58
+ }
59
+ if(stk.length === 0) steps = 0
60
+ else {
61
+ res = Math.max(res, steps)
62
63
+ stk.push([e, steps])
64
65
+ return res
66
+};
67
68
0 commit comments