[LeetCode] 238. Product of Array Except Self


[LeetCode] 238. Product of Array Except Self

문제 정수 배열 nums가 주어졌을 때, answer[i]가 nums[i]를 제외한 모든 요소의 곱과 같도록 하는 배열 answer를 반환합니다. nums의 모든 접두사 또는 접미사의 곱이 32비트 정수에 맞는 것이 보장됩니다. 나눗셈 연산을 사용하지 않고 O(n) 시간 내에 실행되는 알고리즘을 작성해야 합니다. 예시 조건 2 <= nums.length <= 105 -30 <= nums[i] <= 30 The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. 나의 답 public static int[] productExceptSelf(int[] nums){ // to contain 0s Map<Integer,Integer> map = new HashMap<>(); // multiplication of all elemenets except 0s int mul = 1; // result ar...


#java #leetcode #leetcodeproblem

원문링크 : [LeetCode] 238. Product of Array Except Self