C++ code passes INT_MIN INT_MAX corner cases


  • 0
    W

    class Solution {
    public:
    /*
    two cases: 1 is as example, 2 is [1, 2, 50, 75] 0, 99
    */
    vector<string> findMissingRanges(vector<int>& nums, int lower, int upper) {

        vector<string> res;
    
        long low = (long)lower;
        long high = (long)lower;
    
        for(int i=0;i<=nums.size();i++) {
            low = (i==0) ? low:(long)nums[i-1] + 1;
            high = (i == nums.size()) ? (long)upper:(long)nums[i] - 1;
        
            if (low == high) {
                res.push_back(to_string(low));
            } else if (low < high) {
                res.push_back(to_string(low) + "->" + to_string(high)); 
            }
        }
        return res; 
    }
    

    };


Log in to reply
 

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