Solution in Java Beats 100.00%
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to count the number of pairs in the list nums such that the sum of the elem
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to count the number of pairs in the list nums such that the sum of the elements in each pair is less than the given target. This involves iterating through all possible pairs and checking their sums.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize Variables:\n  - n to store the size of the list nums.\n  - count to keep track of the number of valid pairs.\n2. Nested Loops:\n  - The outer loop iterates through each element a in nums.\n  - The inner loop iterates through the elements that come after a in   the list.\n3. Check Pair Sum:\n   - For each pair (a, nums[j]), check if their sum is less than target.\n   - If true, increment the count.\n4. Return the Count:\nAfter checking all pairs, return the count.\n\n# Complexity\n- Time complexity: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# PLEASE UPVOTE \n**feel free to ask in comments**\n# Code\n```java []\nclass Solution {\n    public int countPairs(List<Integer> nums, int target) {\n        int n=nums.size();\n        int count=0;\n        for(int i=0;i<n;i++)\n        {\n            int a=nums.get(i);\n            for(int j=i+1;j<n;j++)\n            {\n                if(a+nums.get(j)<target)\n                    count++;\n            }\n        }\n        return count;\n    }\n}\n```
['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'Java']