publicclassSolution{ public List<String> findMissingRanges(int[] nums, int lower, int upper){ if (lower > upper) returnnull; List<String> res = new LinkedList<>(); int next = lower; for (int i = 0; i < nums.length; i++) { if (nums[i] >= next) { if (nums[i] == next) { next++; continue; } else { res.add(findMissing(next, nums[i] - 1)); next = nums[i] + 1; } } } if (next <= upper) res.add(findMissing(next, upper)); return res; } public String findMissing(int low, int high){ return low == high ? String.valueOf(low) : String.format("%d->%d", low, high); } }