C++ 0ms


  • 0
    class Solution {
    public:
        vector<string> findMissingRanges(vector<int>& nums, int lower, int upper) {
            int left = lower;
            nums.push_back(upper+1);
            int n = nums.size();
            vector<string> ans;
            for(int i=0;i<nums.size();i++) {
                int k = nums[i];
                if(k==left) {
                    left = k+1;
                    continue;
                }
                if(k-1==left) ans.push_back(to_string(left));
                else if(k-1>left){
                    ans.push_back(to_string(left)+"->"+to_string(k-1));
                }
                left = k+1;
            }
            for(auto s:ans) cout << s << endl;
            return ans;
        }
    };
    

Log in to reply
 

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