// True, sorting could take an almost infinite number of processes... wish there was a way without // using the Math class or a loop/recursion interface HighLow { static int[] findLargestAndSmallest(int[] nums) { if(nums == null || nums.length == 0) return null; int min = nums[0]; int max = nums[0]; int index = 0; while(index < nums.length) { min = (min < nums[index]) ? min : nums[index]; max = (max > nums[index]) ? max : nums[index]; index++; } return new int[]{min, max}; } }
interface HighLow {// IMHO with a function this simple and small,// seperating it to even more tiny functions is just overkill and makes the code less readable,// with such small functions you don't seperate for readability, but reusability. :)static int[] findLargestAndSmallest(int[] nums) {if (nums == null || nums.length == 0) return null;- // True, sorting could take an almost infinite number of processes... wish there was a way without
- // using the Math class or a loop/recursion
int max = nums[0];- interface HighLow {
- static int[] findLargestAndSmallest(int[] nums) {
- if(nums == null || nums.length == 0) return null;
- int min = nums[0];
- int max = nums[0];
- int index = 0;
for (int num : nums) {if (max < num) max = num;if (min > num) min = num;- while(index < nums.length) {
- min = (min < nums[index]) ? min : nums[index];
- max = (max > nums[index]) ? max : nums[index];
- index++;
- }
- return new int[]{min, max};
- }