Comments (3)
我又看了一下,确实是优化前缀和。
但0不是最小值,我的解法的唯一区别其实就是没有维护一个最小值。
事实上,tmpSum清零操作和更新最小值是等价的。当出现更小的S(i)的时候,tmpSum才会<0,tmpSum = S(i) - min。
非常有趣,我思考这道题的时候并没有意识到我用到了最小前缀和:)
from leetcode.
我的理解你这个是前缀和。 但是你的0是哪里来的?难道是最小值么?但是0也不一定是最小值吧?如果把你的0换成min,就和我的代码一样了。
function LSS(list) {
const len = list.length;
let max = list[0];
let min = 0;
let sum = 0;
for (let i = 0; i < len; i++) {
sum += list[i];
if (sum - min > max) max = sum - min;
if (sum < min) {
min = sum;
}
}
return max;
}
from leetcode.
我觉得你只是用了对整体”有益与否“这个**吧?如果大于0,那么对整体有利,则保留,否则对整体不利,我们就舍去。 然后用一个变量维护最大值即可
from leetcode.
Related Issues (20)
- 树专题中双色标记法后序和前序写反了 HOT 2
- leetcode/thinkings/tree.md 出错 HOT 1
- some error
- 二分查找专题,寻找最左/右插入位置算法模板错误问题 HOT 9
- possible code error in thinkings/heap.md HOT 1
- link error HOT 4
- link is not correct
- [695.最大岛屿面积,360,面试原题]【每日一题】 HOT 3
- 【专题】 反向思考 HOT 3
- 【专题】 考虑每一项对结果到的贡献
- 【专题】递推方程时间复杂度优化
- 已发布文章的代码错误 HOT 7
- Remove duplicate CPP solution and add Python solution for problem 100.same-tree
- Add OSSF Scorecard security workflow
- 题目的排版可否改一改
- 关于二分法中查找中间点索引的算式 HOT 6
- leetcode-thinkings-tree.md BFS 模版调整 HOT 3
- anki-card 中只有10道题吗?截止到2023.11 HOT 1
- 【每日一题】- 2020-xx-xx - xxx
- 大佬,考虑出一个最短路径的专题吗 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leetcode.