You are viewing a single comment's thread. Return to all comments →
Java 8:
public static List<Long> cubeSum(int n, List<String> operations) { long[][][] a = new long[n][n][n]; List<Long> res = new ArrayList<>(); for(String s: operations) { String[] v = s.split(" "); if(s.contains("UPDATE")) { a[Integer.valueOf(v[1]) - 1][Integer.valueOf(v[2]) - 1][Integer.valueOf(v[3]) - 1] = Long.valueOf(v[4]); } else { int x1 = Integer.valueOf(v[1]) - 1; int y1 = Integer.valueOf(v[2]) - 1; int z1 = Integer.valueOf(v[3]) - 1; int x2 = Integer.valueOf(v[4]) - 1; int y2 = Integer.valueOf(v[5]) - 1; int z2 = Integer.valueOf(v[6]) - 1; long sum = 0; for (int i = x1; i <= x2; i++) { for (int j = y1; j <= y2; j++) { for (int k = z1; k <= z2; k++) { sum += a[i][j][k]; } } } res.add(sum); } } return res; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cube Summation
You are viewing a single comment's thread. Return to all comments →
Java 8: