Can someone explain to me the runtime of this solution and why was it accepted?


  • 0
    S
        if (nums == null || k <= 0) {
    		return new int[0];
    	}
    	
        int[] res = new int[nums.length-k+1];
        int resI = 0;
        for (int i = k-1; i < nums.length; ++i) {
            
            
            // get max of sliding window
            int max = Integer.MIN_VALUE;
            for (int j = i; j > i-k; j--) {
                max = Math.max(max, nums[j]);
            }
            res[resI++]=max;
            
        }
        
        return res;

Log in to reply
 

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