611. 有效三角形的个数

611. Valid Triangle Number

题目描述

LeetCode

LeetCode

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;
}
}

相似题目

参考资料

LeetCode 611. 有效三角形的个数(Valid Triangle Number)的更多相关文章

  1. [Swift]LeetCode611. 有效三角形的个数 | Valid Triangle Number

    Given an array consists of non-negative integers, your task is to count the number of triplets chose ...

  2. Java实现 LeetCode 611 有效三角形的个数(双指针)

    611. 有效三角形的个数 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有效的组合是: 2,3,4 ( ...

  3. Leetcode 611.有效三角形的个数

    有效三角形的个数 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有效的组合是: 2,3,4 (使用第一个 ...

  4. LeetCode:有效三角形的个数【611】

    LeetCode:有效三角形的个数[611] 题目描述 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有 ...

  5. leetcode 611. Valid Triangle Number 、259. 3Sum Smaller(lintcode 918. 3Sum Smaller)

    这两个题几乎一样,只是说611. Valid Triangle Number满足大于条件,259. 3Sum Smaller满足小于条件,两者都是先排序,然后用双指针的方式. 611. Valid T ...

  6. Leetcode 之 Valid Triangle Number

    611. Valid Triangle Number 1.Problem Given an array consists of non-negative integers, your task is ...

  7. LeetCode 611. Valid Triangle Number有效三角形的个数 (C++)

    题目: Given an array consists of non-negative integers, your task is to count the number of triplets c ...

  8. [LeetCode] Valid Triangle Number 合法的三角形个数

    Given an array consists of non-negative integers, your task is to count the number of triplets chose ...

  9. 【LeetCode】611. Valid Triangle Number 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/valid-tri ...

随机推荐

  1. LeetCode 983. Minimum Cost For Tickets

    原题链接在这里:https://leetcode.com/problems/minimum-cost-for-tickets/ 题目: In a country popular for train t ...

  2. LeetCode 743. Network Delay Time

    原题链接在这里:https://leetcode.com/problems/network-delay-time/ 题目: There are N network nodes, labelled 1  ...

  3. CentOS7中使用yum安装nginx和php7.2的方法

    c 1.安装源 安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包. php高版本的yum源地址,有两部分,其中一部分是epel-release,另外一部分来自webtat ...

  4. Redis的移库操作

    1.Redis默认有16个数据库,一般情况下使用0库: 2.移库操作: 将mysets移到一号库: 通过Redis查看器查看: 通过命令查看:

  5. 17-ESP8266 SDK开发基础入门篇--TCP服务器 RTOS版,小试牛刀

    https://www.cnblogs.com/yangfengwu/p/11105466.html 现在开始写... lwip即可以用socket 的API  也可以用 netconn  的API实 ...

  6. [RN] React Native 下实现底部标签(支持滑动切换)

    上一篇文章 [RN] React Native 下实现底部标签(不支持滑动切换) 总结了不支持滑动切换的方法,此篇文章总结出 支持滑动 的方法 准备工作之类的,跟上文类似,大家可点击上文查看相关内容. ...

  7. 【JZOJ6218】【20190615】卖弱

    题目 题解 我写的另一种方法,复杂度是\(O(Tm+nm)\)的,这是huangzhaojun写的题解... #include<cstring> #include<cstdio> ...

  8. 干货 | 10分钟带你彻底了解column generation(列生成)算法的原理附java代码

    OUTLINE 前言 预备知识预警 什么是column generation 相关概念科普 Cutting Stock Problem CG求解Cutting Stock Problem 列生成代码 ...

  9. 加密hashlib模块

    目录 hashlib和hmac模块: hashlib模块: -hash: 特点: 大致流程: 注意: hmac模块: 特点: 注意:hmac模块只接受二进制数据的加密 hashlib和hmac模块: ...

  10. Connection to newtaotao failed. [08001] Could not create connection to database

    jdbc.url=jdbc:mysql://localhost:3306/newtaotao?serverTimezone=UTC&characterEncoding=utf-8 数据库是5. ...