Code
Diff
  • import java.util.*;
    interface HighLow {
      static int[] printLargestAndSmallest(int[] nums) {
        Arrays.sort(nums);
        return new int[] {nums[0], nums[nums.length-1]};
      }
    }
  • 1+
    import java.util.*;
    
    11
    interface HighLow {
    
    22
      static int[] printLargestAndSmallest(int[] nums) {
    
    3
        int min = nums[0], max = nums[0];
    
    4
        for (int n : nums) {
    
    5
          if (n < min) min = n;
    
    6
          if (n > max) max = n;
    
    7
        }
    
    8
        return new int[] {min, max};
    
    4+
        Arrays.sort(nums);
    
    5+
        return new int[] {nums[0], nums[nums.length-1]};
    
    99
      }
    
    1010
    }