创建一个网站多少钱,网址导航已取消是什么意思,网站开发违约解除合同通知函,陕西西铜建设有限责任公司网站2023-10-19每日一题
一、题目编号
1726. 同积元组二、题目链接
点击跳转到题目位置
三、题目描述
给你一个由 不同 正整数组成的数组 nums #xff0c;请你返回满足 a * b c * d 的元组 (a, b, c, d) 的数量。其中 a、b、c 和 d 都是 nums 中的元素#xff0c;且 a ! b…2023-10-19每日一题
一、题目编号
1726. 同积元组二、题目链接
点击跳转到题目位置
三、题目描述
给你一个由 不同 正整数组成的数组 nums 请你返回满足 a * b c * d 的元组 (a, b, c, d) 的数量。其中 a、b、c 和 d 都是 nums 中的元素且 a ! b ! c ! d 。
示例 1
示例 2 提示
1 nums.length 10001 nums[i] 104nums 中的所有元素 互不相同
四、解题代码
class Solution {
public:int tupleSameProduct(vectorint nums) {int n nums.size();int ans 0;unordered_mapint, int cnt;for (int i 0; i n; i) {for(int j i 1; j n; j) {cnt[nums[i] * nums[j]];}}for (auto [k, v] : cnt) {ans v * (v - 1) * 4;}return ans;}
};
五、解题思路
(1) 哈希统计。