1 class Solution { 2 public: 3 string getRange(int start, int end) { 4 ostringstream oss; 5 if (start == end) { 6 oss << start; 7 } else { 8 oss << start << "->" << end; 9 }10 return oss.str();11 }12 vectorfindMissingRanges(int A[], int n, int lower, int upper) {13 vector result;14 int prev = lower - 1;15 for (int i = 0; i < n; i++) {16 if (A[i] - prev > 1) {17 result.push_back(getRange(prev+1, A[i]-1));18 }19 prev = A[i];20 }21 if (upper - prev > 0) result.push_back(getRange(prev+1, upper));22 return result;23 24 }25 };