Golang 148 ms 17.5 MB
Complexity\n- Time complexity: O(n * logn)\n- Space complexity: O(1)\n# Code\n\nfunc countWays(ranges [][]int) int {\n\tsort.Slice(ranges, func(i, j int) bool {
# Complexity\n- Time complexity: $$O(n * logn)$$\n- Space complexity: $$O(1)$$\n# Code\n```\nfunc countWays(ranges [][]int) int {\n\tsort.Slice(ranges, func(i, j int) bool {\n\t\treturn ranges[i][0] < ranges[j][0]\n\t})\n\tresult := 2\n\tfor i, end := 1, ranges[0][1]; i < len(ranges); i++ {\n\t\tif ranges[i][0] > end {\n\t\t\tend = ranges[i][1]\n\t\t\tresult = (result << 1) % 1000000007\n\t\t} else if ranges[i][1] > end {\n\t\t\tend = ranges[i][1]\n\t\t}\n\t}\n\treturn result\n}\n```
['Go']