Find Pivot Index[Leetcode 724]
来源:互联网 发布:网络追逃人员查询系统 编辑:程序博客网 时间:2024/06/05 03:54
Ans
#include <iostream>using namespace std;class Solution {public: int pivotIndex(vector<int>& nums) { int lsum = 0; int rsum = 0; int sum = 0; int len = nums.size(); for (int i = 0; i < len; i++) { sum += nums[i]; } for (int i = 0; i < len; i++) { if (i != 0) { lsum += nums[i-1]; rsum = sum - lsum - nums[i]; if (lsum == rsum) return i; } else { rsum = sum - nums[i]; if (rsum == 0) return 0; } } return -1; }};
阅读全文
0 0
- LeetCode.724 Find Pivot Index
- leetcode 724 Find Pivot Index
- Find Pivot Index[Leetcode 724]
- Find Pivot Index(LeetCode 724)
- LeetCode 724. Find Pivot Index
- LEETCODE: 724. Find Pivot Index
- LeetCode-724. Find Pivot Index
- 724. Find Pivot Index
- LeetCode724. Find Pivot Index
- 724. Find Pivot Index
- [LeetCode]Find Pivot
- Find Pivot Index问题及解法
- LWC 58:724. Find Pivot Index
- leetcode index
- PIVOT
- pivot
- PIVOT
- pivot
- ORACLE ROWNUM分页总结
- 1> python hello word
- JAVA程序员三年从入门到精通的视频资料
- Eclipse解决中文字体设置
- NOT EXISTS
- Find Pivot Index[Leetcode 724]
- 微信小程序——wx.navigateTo中url无法跳转问题(app.json中配置的tabBar与wx.navigateTo中url引用相同页面导致)(2017/12)
- 利用Burp Suite挖掘暗网服务的真实IP
- HBUOJ人见人爱A^B
- Hibernate创建数据表出错:table doesn't exist
- Leetcode: Surrounded Regions
- cpp: 统计输入的单词数量1
- Android Studio必备插件大全
- 看个AV也中招之cve-2010-2553漏洞分析