interface HighLow { static int[] printLargestAndSmallest(int[] nums) { int min = nums[0], max = nums[0]; for (int n : nums) { if (n < min) min = n; if (n > max) max = n; } return new int[] {min, max}; } }
- interface HighLow {
- static int[] printLargestAndSmallest(int[] nums) {
int min = 2147483647, max = -2147483647;for(int n : nums)if(n < min) min = n; elseif(n > max) max = n;return new int[]{min, max};- int min = nums[0], max = nums[0];
- for (int n : nums) {
- if (n < min) min = n;
- if (n > max) max = n;
- }
- return new int[] {min, max};
- }
- }