当前位置:网站首页>1413. 逐步求和得到正数的最小值
1413. 逐步求和得到正数的最小值
2022-08-10 05:43:00 【anieoo】
原题链接:1413. 逐步求和得到正数的最小值
solution:
class Solution {
public:
int minStartValue(vector<int>& nums) {
int n = nums.size();
vector<int> prefix(n + 1);
int s = INT_MAX;
for(int i = 1;i <= n;i++) {
prefix[i] = prefix[i - 1] + nums[i - 1];
s = min(s, prefix[i]);
}
return s < 1 ? 1 - s : 1;
}
};
边栏推荐
- OpenGL学习笔记(LearnOpenGL)-第四部分 着色器
- 21天学习挑战赛--分班
- 交换机的功能和ipv4
- Analysis of minix_super_block.s_ninodes of mkfs.minix.c
- 二次元卡通渲染-着色
- Screen post-processing: Sobel operator to achieve edge detection
- Unity object pool implementation
- OpenGL学习笔记(LearnOpenGL)-第五部分 纹理
- mysql连接报错:Cannot get a connection, pool error Timeout waiting for idle object
- 制作一个启动软盘并用bochs模拟器启动
猜你喜欢
随机推荐
观察者模式-数据池
UnityShader入门精要-高级光照基础
H2数据库如何动态插入数据
超纯水抛光树脂
The use of pointers from the exchange of two data values (C language implementation)
制作一个启动软盘并用bochs模拟器启动
如何实现网格建造系统
npm搭建私服,上传下载包
全网可达,实现备份
socket实现进程间通信
Teach you to change the kernel source code--sysfs virtual file system 2
新手使用 go channel 需要注意的问题
Make a boot floppy and boot with bochs emulator
链表、栈、队列
mysql连接报错:Cannot get a connection, pool error Timeout waiting for idle object
Qt滚动条(QScrollBar)圆角样式问题跟踪
OpenGL学习笔记(LearnOpenGL)-第二部分 绘制三角形
Unity扩展编辑器EditorWindow 小玩意(二)
Qt绘制椭圆曲线的角度问题(离心角和旋转角)
强化学习_10_Datawhale稀疏奖励