题解 | #农场牛类别匹配#
农场牛类别匹配
https://www.nowcoder.com/practice/270db1e1d65b4366a49a517ec7822912
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param breeds int整型vector * @param target_sum int整型 * @return int整型 */ int countMatchingPairs(vector<int>& breeds, int target_sum) { // write code here int count = 0; for (int i = 0; i < breeds.size(); ++i) { for (int j = i + 1; j < breeds.size(); ++j) { if (breeds[i] + breeds[j] == target_sum) ++count; } } return count; } };