Easiest solution|| Beats 100% using binary search algorithm
Intuition\n Describe your first thoughts on how to solve this problem. \nReduce time complexity by binary search algoritm\n# Approach\n Describe your approach t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nReduce time complexity by binary search algoritm\n# Approach\n<!-- Describe your approach to solving the problem. -->\n-Sort the given array\n    nums.sort()\n- Assign left and right as first and last element of array i.e\n    left, right = 0, len(nums) - 1\n- Now apply the binarysearch algorithm\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(logn) except for sort\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def countPairs(self, nums: List[int], target: int) -> int:\n        nums.sort()  \n        count = 0\n        left, right = 0, len(nums) - 1\n        while left < right:\n            if nums[left] + nums[right] < target:\n                count += right - left\n                left += 1\n            else:\n                right -= 1\n        return count\n\n        \n```
['Python3']