当前位置:网站首页>【Likou】1995. Statistical special quadruple
【Likou】1995. Statistical special quadruple
2022-08-09 17:17:00 【dark,】
题目:
给你一个 下标从 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
答案:
class Solution {
public int countQuadruplets(int[] nums) {
int count = 0;
for(int a = 0; a < nums.length - 3; a++){
for(int b = a + 1; b < nums.length - 2; b++){
for(int c = b + 1; c < nums.length - 1; c++){
for(int d = c + 1; d < nums.length; d++){
if(nums[a] + nums[b] + nums[c] == nums[d])count++;
}
}
}
}
return count;
}
}
边栏推荐
- 永磁同步电机电位器调速及数码管实时显示
- 【Postgraduate Work Weekly】(Week 5)
- function calling convention
- Why learn the principles of compiling
- NLP-Reading Comprehension Task Learning Summary Overview
- 深入浅出最优化(5) 共轭梯度下降法
- 蓝桥杯嵌入式备赛
- Stetman的读paper小记:Deep Learning Backdoor Survey (Shaofeng Li, Shiqing Ma, Minhui Xue)
- opencv图像处理及视频处理基本操作
- Candide3人脸动画模型
猜你喜欢
随机推荐
大唐杯5G练习题(二)
[Paper reading] LIME: Low-light Image Enhancement via Illumination Map Estimation (the most complete notes)
【力扣】516. 最长回文子序列
【研究生工作周报】(第三周)
【工具使用】Modbus Poll软件使用详解
将类指针强制转换为void*指针进行传参的使用方法
抱抱脸(hugging face)教程-中文翻译-对预先训练过的模特进行微调
【深度学习】目标检测之评价指标
堆(heap)系列_0x04:堆的内部结构(_HEAP=_HEAP_SEGMENT+_HEAP_ENTRY)
function calling convention
Stetman读peper小记:Defense-Resistant Backdoor Attacks Against DeepNeural Networks in Outsourced Cloud
软件安全基本概念
[Deep learning] attention mechanism
【SQL】175. 组合两个表
【力扣】11. 盛最多水的容器
【工具使用】Keil软件包——知识宝藏库
【研究生工作周报】(第十二周)
Virtualbox 设置共享文件夹
深入浅出最优化(3) 最速下降法与牛顿法
【力扣】593. 有效的正方形









