New Accepted Code-Java


  • 1
    C
    public List<String> findMissingRanges(int[] nums, int lower, int upper) {
            List<String> list = new ArrayList<>();
            long pre = (long)lower-1;
            for(int i = 0; i <= nums.length; i++){
                long after = i==nums.length? (long)upper+1:(long)nums[i];
                if(pre + 2 == after){
                    list.add(String.valueOf(pre+1));
                }else if(pre+2 < after){
                    list.add(String.valueOf(pre+1)+"->"+String.valueOf(after-1));
                }
                pre = after;
            }
            return list;
        }

Log in to reply
 

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