LeetCode刷题笔记(6)按照索引计算int[] 数组中的和([Time Limit Exceeded]问题)
Easy303 Easy633
package easy; public class e303 { private int[] sums; public e303(int[] nums) { sums = new int[nums.length+1]; for (int i = 0; i < nums.length; i++) sums[i+1] = sums[i] + nums[i]; } public int sumRange(int i, int j) { return sums[j+1] - sums[i]; } public static void main(String[] args) { int[] nums = {-2, 0, 3, -5, 2, -1}; e303 obj = new e303(nums); int param_1 = obj.sumRange(2, 5); System.out.println(param_1); } }
儿女情长什么的,最影响我们闯荡江湖了。