Binary search in Python. Fast as heck
Intuition\n Describe your first thoughts on how to solve this problem. \nMake it faster than n^2\n\n# Approach\n Describe your approach to solving the problem. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMake it faster than n^2\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBinary search\n\n# Complexity\n- Time complexity: nlogn\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n\n- Space complexity: n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution(object):\n    def countPairs(self, nums, target):\n\n        n = len(nums)\n        nums.sort()\n        pairs = 0\n\n        for i in range(n):\n            low = i + 1\n            high = n - 1\n            \n            while low <= high:\n                j = (low + high) // 2\n                     \n                if nums[i] + nums[j] < target:\n                    pairs += j - low + 1\n                    low = j + 1\n                else:\n                    high = j - 1\n        \n        return pairs\n```
['Python']