赞
踩
- public class Solution {
- /**
- * @param nums: a list of integers.
- * @param k: length of window.
- * @return: the sum of the element inside the window at each moving.
- */
- public int[] winSum(int[] nums, int k) {
- // write your code here
- if(nums.length==0){
- return nums;
- }
- ArrayList list = new ArrayList();
- int sum = 0;
- for(int i = 0; i < nums.length-(k-1);i++){
- sum = 0;
- int j = i;
- int x=k;
- while(x>0){
- sum +=nums[j];
- j++;
- x--;
- }
- list.add(sum);
- }
- int a[] = new int[list.size()];
- for(int i = 0; i < a.length; i++){
- a[i]=(int)list.get(i);
- }
- return a;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。