Why my status to it says "Time Limit Exceeded"


  • 0
    D
    public class Solution {
        public int[] productExceptSelf(int[] nums) {
            int product;
            int [] arr = new int [nums.length];
            for(int i = 0 ; i< nums.length;i++){
                product = 1;
                for(int j = 0; j<nums.length;j++){
                    if(i != j)
                    product = product*nums[j];
                }
                arr[i] = product;
            }
            return arr;
        }
    }

  • 0
    M

    your code have High time complexity. O(n2).you should modify code to O(1).


  • 0
    M

    He wanted to say O(n) not O(1) in time complexity


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.