7kyu (难度系数kyu阶段数值越大难度越低) 数组分组及求和
作者:互联网
https://www.codewars.com/kata/row-weights/train/java
public class Solution { public static int[] rowWeights (final int[] weights) { int result1 = 0; int result2 = 0; int len = weights.length; if(len==0){ return new int[]{0, 0}; // Do your magic! } for(int i=0;i<len;i++){ if(i%2==0){ result1+=weights[i]; }else{ result2+=weights[i]; } } return new int[]{result1,result2}; } }
大神的Solution
public class Solution { public static int[] rowWeights (final int[] weights) { int totals[] = new int[2], idx = 0; for (int w : weights) totals[(idx++)%2] += w; return totals; } }
标签:7kyu,Solution,totals,int,越低,weights,static,public,难度 来源: https://www.cnblogs.com/ukzq/p/11206366.html