classSolution{public:intsumSubarrayMins(vector<int>& arr){stack<int> s;int n = arr.size();vector<int>leftBound(n,-1);vector<int>rightBound(n, n);for(int i =0; i < n; i++){while(s.size()&& arr[i]<= arr[s.top()])s.pop();leftBound[i]= s.empty()?-1: s.top();s.push(i);}s ={};for(int i = n -1; i >=0; i--){while(s.size()&& arr[i]< arr[s.top()])s.pop();rightBound[i]= s.empty()? n : s.top();s.push(i);}longlong ret =0, mod =1e9+7;for(int i =0; i < n; i++){ret =( ret +(longlong)arr[i]*(i - leftBound[i])*(rightBound[i]- i))% mod;}return ret;}};
js公共方法封装方式都有哪些
全局函数
function greet(name) {console.log("Hello, " name "!");
}greet("Alice"); // 调用全局函数对象字面量
var utils {add: function(a, b) {return a b;},subtract: function(a, b) {return a - b;}…