TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Algorithmic Puzzle: Continuous Increasing Subsequences

1 点作者 bor0大约 4 年前

1 comment

cousin_it大约 4 年前
It&#x27;s much simpler, if there&#x27;s an increasing run of length k, it contains k(k+1)&#x2F;2 subruns. So you can just do one pass over the array, keeping track of the length of the current run.<p><pre><code> function f(arr) { var j=0, ret=0; for (var i=1; i&lt;=arr.length; i++) { if (i==arr.length || arr[i]&lt;=arr[i-1]) { ret += (i-j)*(i-j+1)&#x2F;2; j = i; } } return ret; }</code></pre>