子数组之和为零 lintcode
2016-04-14 22:13
204 查看
给定一个整数数组,找到和为零的子数组。你的代码应该返回满足要求的子数组的起始位置和结束位置。
样例
给出
样例
给出
[-3, 1, 2, -3, 4],返回
[0, 2]或者
[1, 3].
class Solution { public: /** * @param nums: A list of integers * @return: A list of integers includes the index of the first number * and the index of the last number */ vector<int> subarraySum(vector<int> nums){ // write your code here vector<int> result; int n = nums.size(); int sum = 0; for(int i = 0;i<n;i++){ for(int j = i;j<n;j++) { sum += nums[j]; if(sum == 0) { result.push_back(i); result.push_back(j); return result; } } } //return result; } };
相关文章推荐
- 使用jspSmartUpload组件进行文件上传、下载
- ubuntu 14.04 x64下安装libreoffice
- 设置xx-net,访问youtube等国外网站
- 【leetcode】225. Implement Stack using Queues
- 【弱校胡策】2016.4.14 (bzoj2164)最短路+状压DP+矩阵乘法+高斯消元+树链剖分+线段树+背包DP
- eglMakeCurrent, eglSwapBuffers, glFlush, glFinish
- mysql5.7.11编译安装以及修改root密码小结
- Centos 7.0 忘记密码,如何重置
- 学习
- DSS 搭建手机流媒体服务器
- showModelDialog的使用(二):提供下载功能
- 深入浅出 JavaScript 中的 this
- 在IIS7.5打开网页的时候,提示: HTTP 错误 500.0 - Internal Server Error 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\aspnet_filter.dll" 上。解决方法
- Score
- html标签属性大全
- showModelDialog的使用(一)
- 复利计算再升级——连接数据库
- 关于序列化
- in与exist,not in与not exsit的区别
- php中的CURL库