当前位置:网站首页>Leetcode 1995. Statistics special quads (brute force enumeration)
Leetcode 1995. Statistics special quads (brute force enumeration)
2022-06-11 10:31:00 【I'm not xiaohaiwa~~~~】

To give you one Subscript from 0 Start Array of integers for nums , Returns a that meets the following conditions Different Four tuple (a, b, c, d) Of number :
- nums[a] + nums[b] + nums[c] == nums[d] , And
- a < b < c < d
Example 1:
Input :nums = [1,2,3,6]
Output :1
explain : The only Quad that meets the requirements is (0, 1, 2, 3) because 1 + 2 + 3 == 6 .
Example 2:
Input :nums = [3,3,6,4,5]
Output :0
explain :[3,3,6,4,5] There are no required quads in the .
Example 3:
Input :nums = [1,1,1,3,5]
Output :4
explain : Meet the requirements of 4 The four tuples are as follows :
- (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
Tips :
- 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;
}
};
边栏推荐
- 金仓数据KingbaseES 批量创建数据库对象
- Start jar
- Browserfetcher class for getting started with puppeter
- Cas de rectification du CEM rayonné par des équipements électroniques
- Correct opening method of RPC | understand go native net/rpc package
- Source code of digital collection app system
- Browser class for getting started with puppeter
- NGUI,冷却效果
- [Objective-C] differences between structs and classes
- 【MYSQL】存储过程的使用
猜你喜欢

【机器学习理论】True Positive, True Negative, False Positive, False Negative概念

Kingbasees create database objects in batch

Tiktok encounters cultural conflict in the UK, and many employees leave in a short time

NFT产品是有生命的

以银行异业合作为例,浅谈小程序生态的建设

金仓数据库KingbaseES中的PL/SQL 编译检查

Some code fragments of a universal and confession wall system developed by PHP

Leetcode 1961. 检查字符串是否为数组前缀

Introduction to ZigBee module wireless transmission star topology networking structure

【CV基础】颜色:RGB/HSV/Lab
随机推荐
Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
Use bat to write to the first line of the file
修复UICollectionView 没有到达底部安全区的问题
数字藏品app系统源码
Initial deployment of Servlet
Start jar
选择DC-DC开关电源控制器的实战过程
以银行异业合作为例,浅谈小程序生态的建设
详述用网络分析仪测量DC-DC和PDN
硬件描述语言HDL
FPGA infrastructure [reference ug998]
MD5学习
[Bert]: Calculation of last ave state when training tasks with similar Bert semantics
What is digital twin? A real-time and virtual representation
MySQL transaction
班组级安全培训,新员工入职培训教育课件,全内容PPT套用
NGUI,选择性别男女
After four years of outsourcing, it was abandoned
MySQL基础篇常用约束总结下篇
Installing mysql5.7 for Linux