第72场双周赛

5996. 统计数组中相等且可以被整除的数对 - 力扣(LeetCode) (leetcode-cn.com)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
int countPairs(vector<int>& nums, int k) {
int n = nums.size();
int res = 0;
for (int i = 0; i < n; i ++)
for (int j = i + 1; j < n; j ++) {
if (nums[i] == nums[j]) {
if (((i * j) % k) == 0) res ++;
}
}
return res;
}
};

5997. 找到和为给定整数的三个连续整数 - 力扣(LeetCode) (leetcode-cn.com)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
vector<long long> sumOfThree(long long num) {
long long mid = num / 3;
long left = mid - 1, right = mid + 1;
vector<long long> res;
if (mid + left + right == num) {
res.push_back(left);
res.push_back(mid);
res.push_back(right);
}
return res;
}
};

5998. 拆分成最多数目的偶整数之和 - 力扣(LeetCode) (leetcode-cn.com)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
vector<long long> maximumEvenSplit(long long finalSum) {
if (finalSum % 2 == 1) return vector<long long>{};

vector<long long> res;
long long i = 2;
while (finalSum >= i) {
res.push_back(i);
finalSum -= i;
i += 2;
}
res[res.size() - 1] += finalSum;
return res;
}
};

第72场双周赛
https://2w1nd.github.io/2022/02/20/LC周赛/第72场双周赛/
作者
w1nd
发布于
2022年2月20日
许可协议