标签:
int removeElement(vector<int> &A, int elem) { int i = 0; int pointer = A.size() - 1; while (i <= pointer) { if (A[i] == elem) { A[i] = A[pointer]; --pointer; } else { ++i; } } return pointer + 1; }
public ArrayList<Integer> subarraySum(int[] nums) { ArrayList<Integer> ret = new ArrayList<Integer>(); for (int i = 0; i < nums.length; ++i) { int sum = 0; for (int j = i; j < nums.length; ++j) { sum += nums[j]; if (sum == 0) { ret.add(i); ret.add(j); return ret; } } } return ret; }
标签:
原文地址:http://www.cnblogs.com/fripside/p/4607245.html