<p>You are given a <strong>0-indexed</strong> 2D integer array <code>nums</code> representing the coordinates of the cars parking on a number line. For any index <code>i</code>, <code>nums[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> where <code>start<sub>i</sub></code> is the starting point of the <code>i<sup>th</sup></code> car and <code>end<sub>i</sub></code> is the ending point of the <code>i<sup>th</sup></code> car.</p>

<p>Return <em>the number of integer points on the line that are covered with <strong>any part</strong> of a car.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [[3,6],[1,5],[4,7]]
<strong>Output:</strong> 7
<strong>Explanation:</strong> All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [[1,3],[5,8]]
<strong>Output:</strong> 7
<strong>Explanation:</strong> Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 100</code></li>
	<li><code>nums[i].length == 2</code></li>
	<li><code><font face="monospace">1 &lt;= start<sub>i</sub>&nbsp;&lt;= end<sub>i</sub>&nbsp;&lt;= 100</font></code></li>
</ul>

class Solution:
    def numberOfPoints(self, nums: List[List[int]]) -> int:

        # sort in ascending order or the start time
        for i in range(len(nums)):
            for j in range(i + 1, len(nums)):
                if (nums[i][0] > nums[j][0]):
                    temp = nums[i]
                    nums[i] = nums[j]
                    nums[j] = temp
        
        print(nums)

        # find the solution
        soln = 0
        for i, num in enumerate(nums):
            if (i == 0):
                soln += num[1] - num[0] + 1
            else:
                # conflict
                if (num[0] <= nums[i - 1][1]):
                    if (num[1] > nums[i - 1][1]):
                        soln += num[1] - nums[i - 1][1]
                    else:
                        num[1] = nums[i - 1][1]
                else:
                    soln += num[1] - num[0] + 1
        
        return soln

        # # sort the array
        # for i in range(len(nums)):
        #     for j in range(i + 1, len(nums)):
        #         # compare the start numbers
        #         if (nums[i][0] > nums[j][0]):
        #             temp = nums[i]
        #             nums[i] = nums[j]
        #             nums[j] = temp
        
        # # merge if overlap
        # i = 0
        # n = len(nums)
        # while (i < n):

        #     j = i + 1
        #     while (j < n):
        #         # overlap, merge them
        #         if (max(nums[i][0], nums[j][0]) <= min(nums[i][1], nums[j][1])):
        #             nums.insert(i, [min(nums[i][0], nums[j][0]), max(nums[i][1], nums[j][1])])
        #             nums.pop(i + 1)
        #             nums.pop(j)
        #             n = len(nums)    
        #             continue
        #         j += 1
            
        #     n = len(nums)
        #     i += 1

        # # count the non-overlapping
        # count = 0
        # for num in nums:
        #     count += num[1] - num[0] + 1

        # return count
88