2026/6/20 3:34:49
网站建设
项目流程
网站空间租用哪家好,电子商务网站建设技术规范,山东建设科技产品推广网站,手机页面制作代码2110: 股票平滑下跌阶段的数目示例 1 的 prices[3,2,1,4]#xff0c;按照子数组的右端点下标分组#xff0c;有这些连续递减子数组#xff1a;右端点 i0#xff1a;[3]右端点 i1#xff1a;[3,2]#xff0c;[2]右端点 i2#xff1a;[3,2,1]#xff0c;[2,1]#xff0c…2110: 股票平滑下跌阶段的数目示例 1 的 prices[3,2,1,4]按照子数组的右端点下标分组有这些连续递减子数组右端点 i0[3]右端点 i1[3,2][2]右端点 i2[3,2,1][2,1][1]右端点 i3[4]思路在遍历 prices 的同时统计当前这段连续递减的长度 last_d。long long ans 1; // 第一个元素自己算一个1 prices.length 10^5class Solution { public: long long getDescentPeriods(vectorint prices) { int nprices.size(),last_d1; // 当前连续平滑段长度≥1 long long ans1; for(int i1;in;i){ if(prices[i-1]-prices[i]1) last_d; else last_d1; anslast_d; } return ans; } };