explanation Note: Please solve it without division and in O(n). Follow up:Could you solve it with constant space complexity? (The output array does not count as extra space for the purpose of space complexity analysis.) go through the array from begin to end go through the array from end to begin code 1234567891011121314151617181920 class { public int[] productExceptSelf(int[] nums) { if (nums == null || nums.length == 0) { return null; } int[] result = new int[nums.length]; result[0] = 1; for (int i = 1; i < nums.length; i++) { result[i] = result[i - 1] * nums[i - 1]; } int temp = 1; for (int i = nums.length - 1; i >= 0; i--) { result[i] = result[i] * temp; temp = temp * nums[i]; } return result; }} 赞微海报分享
近期评论