How to analysis the time and space of my code?


  • 0
    H
     public int maximumGap(int[] nums) {
    	 if(nums.length<2){
    		 return 0;
    	}
    		 
    	Arrays.sort(nums);
    	int max  = nums[1]-nums[0];
    	for(int i = 2;i<nums.length;i++){
    		if(nums[i]-nums[i-1]>max){
    			max = nums[i]-nums[i-1];
    		}
    	}
    	return max;	        
    }
    

    How to analysis the time and space complexity of my code?


Log in to reply
 

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