当前位置:网站首页>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;
}
};
边栏推荐
- Handwritten code call, apply, bind
- 電子設備輻射EMC整改案例
- [MySQL] use of stored procedures
- Dimension types for different CV tasks
- 【机器学习理论】True Positive, True Negative, False Positive, False Negative概念
- 数字藏品系统开发源码搭建
- About CI framework batch export to compressed file
- 【高并发】关于线程池,蚂蚁金服面试官问了我这些内容!!
- [Objective-C] dynamically create controls
- 微信小程序之点餐系统附源码
猜你喜欢

为什么DDRx的电源设计时需要VTT电源

After four years of outsourcing, it was abandoned

Datagrip 2022, datagrip function

Cadence OrCAD capture design method to avoid misoperation graphic tutorial

Sys in kingbasees_ Checksums bad block detection function

MySQL basic learning notes 03

金仓数据库KingbaseES UDP监控工具的使用

选择DC-DC开关电源控制器的实战过程

Mouse click coordinate transformation generation

Wechat applet ordering system with source code
随机推荐
Waiting event enq: Ko - some feasible processing methods for fast object checkpoint
用真金做的电路板——金手指
What are the ABAP keywords and syntax that cannot be used in the ABAP cloud environment?
Interview review - closure
Address of my bookmark
MySQL permission management and backup
Sys in kingbasees_ Checksums bad block detection function
MySQL foundation part common constraints summary part 2
Habitable planet
Ngui, floating blood
Kingbasees create database objects in batch
Mouse click coordinate transformation generation
C语言课程设计
Common techniques for handling dates
知识点滴 - 性格分析-四类法
rpc的正确打开方式|读懂Go原生net/rpc包
[MySQL] use of stored procedures
Installing mysql5.7 for Linux
Knowledge drop - personality analysis - four types of method
Detailed explanation of Lora module wireless transceiver communication technology