https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/description/
Count Pairs Whose Sum is Less than Target - LeetCode
Can you solve this real interview question? Count Pairs Whose Sum is Less than Target - Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target. Exampl
leetcode.com
1 2 3 4 5 6 7 8 9 10 | class Solution: def countPairs(self, nums: List[int], target: int) -> int: answer = 0 for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] + nums[j] < target: answer += 1 return answer | cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2643. Row With Maximum Ones (1) | 2024.01.02 |
---|---|
leetcode 2788. Split Strings by Separator (1) | 2024.01.02 |
leetcode 2729. Check if The Number is Fascinating (0) | 2023.12.29 |
leetcode 2903. Find Indices With Index and Value Difference I (0) | 2023.12.28 |
leetcode 2923. Find Champion I (0) | 2023.12.28 |
댓글