C++ Intervals Merging
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nMerge intervals.\n# Com
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMerge intervals.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$O(n\\log{n})$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    static bool cmp(vector<int> a, vector<int> b) {\n        return a[0] < b[0];\n    }\n\n    int countWays(vector<vector<int>>& ranges) {\n        sort(ranges.begin(), ranges.end(), cmp);\n        int countGroup = 0;\n        int curBegin = -1;\n        int curEnd = -1;\n        for(vector<int> r : ranges) {\n            int begin = r[0], end = r[1];\n            if(begin <= curEnd) {\n                curEnd = max(curEnd, end);\n            } else {\n                countGroup++;\n                curBegin = begin;\n                curEnd = end;\n            }\n        }\n        int ways = 1;\n        for(int i = 0; i < countGroup; i++) {\n            ways = ways << 1;\n            ways %= (7 + int(1e9));\n        }\n        return ways;\n    }\n};\n```
['C++']