LeetCode 611. 有效三角形的个数(Valid Triangle Number)
611. 有效三角形的个数
611. Valid Triangle Number
LeetCode611. Valid Triangle Number中等
Java 实现
import java.util.Arrays;
class Solution {
public int triangleNumber(int[] nums) {
int count = 0, len = nums.length;
Arrays.sort(nums);
for (int i = len - 1; i > 1; i--) {
int left = 0, right = i - 1;
while (left < right) {
if (nums[left] + nums[right] > nums[i]) {
count += right - left;
right--;
} else {
left++;
}
}
}
return count;
}
}
相似题目
参考资料
- https://leetcode-cn.com/problems/valid-triangle-number/
- https://leetcode.com/problems/valid-triangle-number/
LeetCode 611. 有效三角形的个数(Valid Triangle Number)的更多相关文章
- [Swift]LeetCode611. 有效三角形的个数 | Valid Triangle Number
Given an array consists of non-negative integers, your task is to count the number of triplets chose ...
- Java实现 LeetCode 611 有效三角形的个数(双指针)
611. 有效三角形的个数 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有效的组合是: 2,3,4 ( ...
- Leetcode 611.有效三角形的个数
有效三角形的个数 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有效的组合是: 2,3,4 (使用第一个 ...
- LeetCode:有效三角形的个数【611】
LeetCode:有效三角形的个数[611] 题目描述 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有 ...
- leetcode 611. Valid Triangle Number 、259. 3Sum Smaller(lintcode 918. 3Sum Smaller)
这两个题几乎一样,只是说611. Valid Triangle Number满足大于条件,259. 3Sum Smaller满足小于条件,两者都是先排序,然后用双指针的方式. 611. Valid T ...
- Leetcode 之 Valid Triangle Number
611. Valid Triangle Number 1.Problem Given an array consists of non-negative integers, your task is ...
- LeetCode 611. Valid Triangle Number有效三角形的个数 (C++)
题目: Given an array consists of non-negative integers, your task is to count the number of triplets c ...
- [LeetCode] Valid Triangle Number 合法的三角形个数
Given an array consists of non-negative integers, your task is to count the number of triplets chose ...
- 【LeetCode】611. Valid Triangle Number 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/valid-tri ...
随机推荐
- Vue --- 基础简介
目录 Vue简介 1.什么是Vue 2.为什么要学习Vue 3.special -- 特点 4.如何使用vue Vue使用 1.如何使用vue 2.插值表达式 3.文本指令 4.事件指令 5.属性指令 ...
- Support Vector Machines
支持向量机SVM. 简介 SVM核函数包括线性核函数.多项式核函数.径向基核函数.高斯核函数.幂指数核函数.拉普拉斯核函数.ANOVA核函数.二次有理核函数.多元二次核函数.逆多元二次核函数以及Sig ...
- c++ 去掉所有空格及换行符
string get_string(string res){ //删除换行符 int r = res.find('\r\n'); while (r != string::npos) { if (r ! ...
- C++ EH Exception(0xe06d7363)----抛出过程
C++ EH Exception是Windows系统VC++里对c++语言的throw的分类和定义,它的代码就是0xe06d7363.在VC++里其本质也是SEH结构化异常机制.在我们分析用户崩溃的例 ...
- 关于java项目跑着跑着就挂掉的问题
部署项目后,安装redis,从redis中获取数据,或一些数据库查询操作,服务器cpu和内存占用率突增.
- Hash算法解决冲突的四种方法
Hash算法解决冲突的方法一般有以下几种常用的解决方法 1, 开放定址法: 所谓的开放定址法就是一旦发生了冲突,就去寻找下一个空的散列地址,只要散列表足够大,空的散列地址总能找到,并将记录存入 公式为 ...
- Error:(1, 1) java: 非法字符: '\ufeff'
找到 java 文件. 使用 notepad 打开,转码,并保存即可.
- OPPO-Java面试-社招-一面(2019/07)
个人情况 2017年毕业,普通本科,计算机科学与技术专业,毕业后在一个二三线小城市从事Java开发,2年Java开发经验.做过分布式开发,没有高并发的处理经验,平时做To G的项目居多.写下面经是希望 ...
- 第07组 Alpha冲刺(5/6)
队名:摇光 队长:杨明哲 组长博客:求戳 作业博客:求再戳 队长:杨明哲 过去两天完成了哪些任务 文字/口头描述:依然在完善网页编辑器的后端. 展示GitHub当日代码/文档签入记录:(组内共用,已询 ...
- mysql查询列定义,是否自增等
SELECT ORDINAL_POSITION AS Colorder, Column_Name AS ColumnName, data_type AS TypeName, COLUMN_COMMEN ...