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 ...
随机推荐
- GITHUB常见命令
1 常用 $ git remote add origin git@github.com:yeszao/dofiler.git # 配置远程git版本库 $ git pull origin master ...
- python - django 控制台输出 sql 语句
只需要在 settings.py 文件中加入以下配置即可. LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers ...
- [CSS] prefers-reduced-motion
The prefers-reduced-motion CSS media feature is used to detect if the user has requested that the sy ...
- LeetCode 877. Stone Game
原题链接在这里:https://leetcode.com/problems/stone-game/ 题目: Alex and Lee play a game with piles of stones. ...
- LeetCode 1061. Lexicographically Smallest Equivalent String
原题链接在这里:https://leetcode.com/problems/lexicographically-smallest-equivalent-string/ 题目: Given string ...
- (尚018-第二章2.1)Vue使用vue-cli创建模板项目
2.1.1 1)vue-cli是官方提供的脚手架工具(注意:脚手架本身是个库) 2)github:https://github.com/vuejs/vue-cli 3)作用:从https://gith ...
- s3git 使用git 管理云存储
使用s3git 我们可以方便的基于git协议进行s3存储数据的版本管理,同时也提供了一个方便的golang 包, 我们可以集成到我们的应用中,但是有一点,目前已经没有再更新过了,但是设计理论很不错,实 ...
- 21-ESP8266 SDK开发基础入门篇--C# TCP客户端 , 控制LED亮灭
https://www.cnblogs.com/yangfengwu/p/11192603.html 由于是台式机,,没有插无线网卡...所以呢我就用调试助手监控下数据 后期让WIFI连接路由器的时候 ...
- 记一次CDH集群日志数据清理
背景 集群运行一段时间(大概一月多)后,cloudera manager管理界面出现爆红,爆红的组件有hdfs.zookeeper. 发现问题 点击详细内容查看,报日志空间不够的错误.初步判断是各个组 ...
- 鱼塘钓鱼(fishing)(信息学奥赛一本通 1373)
[问题描述] 有N个鱼塘排成一排(N<100),每个鱼塘中有一定数量的鱼,例如:N=5时,如下表: 即:在第1个鱼塘中钓鱼第1分钟内可钓到10条鱼,第2分钟内只能钓到8条鱼,……,第5分钟以后再 ...