public class Solution {
/*
* @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
*/
public List<Integer> subarraySum(int[] nums) {
// write your code here
ArrayList<Integer> res = new ArrayList<Integer>();
for(int i = 0;i < nums.length ; i ++){
int sum = 0;
for(int j = i; j < nums.length ;j++){
sum = sum + nums[j];
if(sum == 0){
res.add(i);
res.add(j);
return res;
}
}
}
return res;
}
}

这个题目两个循环就实现了,但一般两个循环就实现了的题性能都不够好,都应该还有比较好的算法。
这个题和string里那个longest common string有类似之处,都可以dp.稍后再写写这个了。

subarray sum的更多相关文章

  1. [LeetCode] Maximum Size Subarray Sum Equals k 最大子数组之和为k

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  2. [LeetCode] Minimum Size Subarray Sum 最短子数组之和

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  3. [LintCode] Minimum Size Subarray Sum 最小子数组和的大小

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  4. Subarray Sum & Maximum Size Subarray Sum Equals K

    Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code sho ...

  5. [LintCode] Continuous Subarray Sum II

    Given an integer array, find a continuous rotate subarray where the sum of numbers is the biggest. Y ...

  6. leetcode面试准备:Minimum Size Subarray Sum

    leetcode面试准备:Minimum Size Subarray Sum 1 题目 Given an array of n positive integers and a positive int ...

  7. [LeetCode] Minimum Size Subarray Sum 解题思路

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  8. Subarray Sum Closest

    Question Given an integer array, find a subarray with sum closest to zero. Return the indexes of the ...

  9. LeetCode OJ 209. Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  10. Maximum Subarray Sum

    Maximum Subarray Sum 题意 给你一个大小为N的数组和另外一个整数M.你的目标是找到每个子数组的和对M取余数的最大值.子数组是指原数组的任意连续元素的子集. 分析 参考 求出前缀和, ...

随机推荐

  1. (9/24) 图片跳坑大战--css分离与图片路径处理

    前言: 在上一节当中,我们把小图片打包成Base64格式(打包到了js当中).我们也算是对webpack对图片的打包有个基本了解. 本节我们准备把css从JavasScript代码中分离出来,这会遇到 ...

  2. IDEA VM设置

    1.IDEA vm options -server -Xms800m -Xmx800m -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128 ...

  3. 微信小程序 用户登录 服务器端(TP5.1)实现

    先来看官方提供的流程图: 客户端: 小程序客户端通过 wx.login() 获取登录code , 然后将code当做参数传递到服务器. getToken(){ var that = this; wx. ...

  4. maven项目发布到tomcat的错误

    Could not publish to the server. java.lang.IndexOutOfBoundsException "Updating status for Tomca ...

  5. 将font-size设置为 12px 以下,Chrome浏览器只能显示12px怎么办?

    将字体大小设置为12px以下,而Chrome浏览器依然只显示12px,因为 Chrome 这款任性的浏览器做了如下限制: 1. font-size 有一个最小值 12px(不同操作系统.不同语言可能限 ...

  6. Java 集合类实现原理

    转载自:http://blog.csdn.net/qq_25868207/article/details/55259978 :##ArrayList实现原理要点概括 参考文献:http://zhang ...

  7. SQLLDR导入乱码问题的解决

    SQLLDR导入乱码问题的解决   处理过程: 1.本地建立控制文件   load data infile 'd:\TMP_KAITOUSHUJU.csv' into table TMP_KAITOU ...

  8. Windows驱动开发VS2012 DDK/WDK的环境配置

    [开发Windows驱动的配置是很必要的,下文将详细介绍VS2012如何配置驱动开发环境] [转载] 以下部分内容是转载博客:http://blog.csdn.net/huangxy10/articl ...

  9. python 之C3算法

    C3算法只要针对的Python2.3版本之后出现的新式类MRO(method resolution order) -------继承方法查询顺序;而经典类MRO则遵循的是深度优先遍历(树形结构) (1 ...

  10. etcd集群部署与遇到的坑

    在k8s集群中使用了etcd作为数据中心,在实际操作中遇到了一些坑.今天记录一下,为了以后更好操作. ETCD参数说明 —data-dir 指定节点的数据存储目录,这些数据包括节点ID,集群ID,集群 ...