当前位置:网站首页>Leetcode 1995. 统计特殊四元组(暴力枚举)
Leetcode 1995. 统计特殊四元组(暴力枚举)
2022-06-11 10:28:00 【我不是萧海哇~~~~】

给你一个 下标从 0 开始 的整数数组 nums ,返回满足下述条件的 不同 四元组 (a, b, c, d) 的 数目 :
- nums[a] + nums[b] + nums[c] == nums[d] ,且
- a < b < c < d
示例 1:
输入:nums = [1,2,3,6]
输出:1
解释:满足要求的唯一一个四元组是 (0, 1, 2, 3) 因为 1 + 2 + 3 == 6 。
示例 2:
输入:nums = [3,3,6,4,5]
输出:0
解释:[3,3,6,4,5] 中不存在满足要求的四元组。
示例 3:
输入:nums = [1,1,1,3,5]
输出:4
解释:满足要求的 4 个四元组如下:
- (0, 1, 2, 3): 1 + 1 + 1 == 3
- (0, 1, 3, 4): 1 + 1 + 3 == 5
- (0, 2, 3, 4): 1 + 1 + 3 == 5
- (1, 2, 3, 4): 1 + 1 + 3 == 5
提示:
- 4 <= nums.length <= 50
- 1 <= nums[i] <= 100
Code:
class Solution {
public:
int countQuadruplets(vector<int>& nums) {
int cnt=0;
for(int i=0;i<nums.size();i++)
{
for(int j=i+1;j<nums.size();j++)
{
for(int k=j+1;k<nums.size();k++)
{
for(int l=k+1;l<nums.size();l++)
{
if((nums[i] + nums[j] + nums[k]) == nums[l] )
{
cnt++;
}
}
}
}
}
return cnt;
}
};
边栏推荐
猜你喜欢

With determination to forge ahead, JASMINER continues to deepen its brand strength

What is the SOA or ASO of MOSFET?

Picture rule page turning

After four years of outsourcing, it was abandoned

UGUI

Sys in kingbasees_ Checksums bad block detection function

安装MySQL ,出现由于找不到 MSVCR120.dll,无法继续执行代码解决方法”

Ugui mouse click diffusion UI effect

Fix the problem that uicollectionview does not reach the bottom security zone

MySQL基础篇常用约束总结下篇
随机推荐
Mysql--事务
MySQL基础篇常用约束总结下篇
Common techniques for handling dates
吴恩达机器学习课程-第七周
【机器学习理论】True Positive, True Negative, False Positive, False Negative概念
【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode
金仓数据库KingbaseES UDP监控工具的使用
详解2.5G/5G/10G Base-T以太网接口物理层一致性测试!
[audio and video] Introduction to SEI
Kingbasees create database objects in batch
New feature of ES6 - arrow function
Arbitrum 基础架构:快速入门
After four years of outsourcing, it was abandoned
Development and source code construction of digital collection system
Mysql--索引
使用bat向文件的第一行中写入内容
With determination to forge ahead, JASMINER continues to deepen its brand strength
Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
What is digital twin? A real-time and virtual representation
[high concurrency] the interviewer of ant financial asked me about thread pool!!