[Java] Loop solution with detailed explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks to find the number of pairs (i, j) in the list where the sum of the el
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks to find the number of pairs `(i, j)` in the list where the sum of the elements at those indices is less than a given target. The immediate thought is to check every possible pair of elements and count those that meet the condition. Since the list size is relatively small, a brute-force approach that checks all pairs is feasible.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize a counter variable `count` to `0` to keep track of the number of valid pairs.\n2. Use two nested loops to iterate over all possible pairs of indices `(i, j)`:\n   - The outer loop runs from `i = 0` to `n-2`, representing the first element in the pair.\n   - The inner loop runs from `j = i+1` to `n-1`, representing the second element in the pair.\n3. For each pair `(i, j)`, check if the sum of `nums.get(i) + nums.get(j)` is less than the target value.\n   - If the condition is true, increment the `count` by 1.\n4. After iterating through all pairs, return the value of `count`, which represents the number of pairs that satisfy the condition.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n  - The time complexity is $$O(n^2)$$, where `n` is the number of elements in the list. This is because we are evaluating each pair `(i, j)` in a nested loop.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n  - The space complexity is $$O(1)$$, as the algorithm only uses a few variables (e.g., `count`, and loop indices) and does not require any additional data structures.\n\n# Code\n```java []\nclass Solution {\n    public int countPairs(List<Integer> nums, int target) {\n        int count = 0;\n        int n = nums.size();\n        \n        for (int i = 0; i < n - 1; i++) {\n            for (int j = i + 1; j < n; j++) {\n                if (nums.get(i) + nums.get(j) < target) {\n                    count++;\n                }\n            }\n        }\n        \n        return count;\n    }\n}\n\n```
['Java']