Finally it passed......


  • 0
    Y
    public class Solution {
        public List<String> findMissingRanges(int[] nums, int lower, int upper) {
            List<String> res = new ArrayList<>();
            long pre = (long)lower - 1;
            for(int i = 0; i <= nums.length; i++){
                long after = 0;
                if(i == nums.length){
                    after = (long)upper + 1;
                }else{
                    after = nums[i];
                }
                if(after - pre == 2){
                    String s = String.valueOf(pre + 1);
                    res.add(s);
                }else if(after - pre > 2){
                    String s = String.valueOf(pre + 1) + "->" + String.valueOf(after - 1);
                    res.add(s);
                }
                pre = after;
            }
            return res;
        }
    }
    I don't think the test case here is reasonable. It has no sense.

Log in to reply
 

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