Should be "Medium" or even "Easy".. Just with a little Greedy.

class Solution {
public:
/**
* @param S: A list of integers
* @return: An integer
*/
int triangleCount(vector<int> &S) {
int n = S.size();
if(n < ) return ; sort(S.begin(), S.end());
int ret = ; for(int e = n - ; e > ; e --)
{
int s = , m = e - ;
while(s < m)
{
if( (S[s] + S[m]) <= S[e])
{
s ++;
}
else
{
ret += m - s;
m --;
}
}
} return ret;
}
};

LintCode "Triangle Count"的更多相关文章

  1. Triangle Count

    Given an array of integers, how many three numbers can be found in the array, so that we can build a ...

  2. LintCode 391: Count Of Airplanes

    LintCode 391: Count Of Airplanes 题目描述 给出飞机的起飞和降落时间的列表,用 interval 序列表示. 请计算出天上同时最多有多少架飞机? 样例 对于每架飞机的起 ...

  3. 【Lintcode】382.Triangle Count

    题目: Given an array of integers, how many three numbers can be found in the array, so that we can bui ...

  4. lintcode :Count and Say 报数

    题目: 报数 报数指的是,按照其中的整数的顺序进行报数,然后得到下一个数.如下所示: 1, 11, 21, 1211, 111221, ... 1 读作 "one 1" -> ...

  5. lintcode :Count 1 in Binary 二进制中有多少个1

    题目: 二进制中有多少个1 49% 通过 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111 ...

  6. LintCode: Triangle

    C++ 逆推 class Solution { public: /** * @param triangle: a list of lists of integers. * @return: An in ...

  7. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  8. lintcode算法周竞赛

    ------------------------------------------------------------第七周:Follow up question 1,寻找峰值 寻找峰值 描述 笔记 ...

  9. [Swift]LeetCode120. 三角形最小路径和 | Triangle

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

随机推荐

  1. OpenFlow Switch学习笔记(二)——OpenFlow Ports

    OpenFlow Ports是OpenFlow Switch与剩余网络之间传递Packet的网络接口.OpenFlow Switches之间通过OpenFlow Ports彼此相互逻辑连接.一个Ope ...

  2. 如何写 github wiki

    在你库里面的文件夹下 点击wiki进入编辑页面 如何编辑: header以#开始, #代表一级header, ##代表二级header... 段落直接以空行分隔. 每行后面加两个以上的空格 分条列举的 ...

  3. 单页web应用(SPA)的简单介绍

    单页 Web 应用 (single-page application 简称为 SPA) 是一种特殊的 Web 应用.它将所有的活动局限于一个Web页面中,仅在该Web页面初始化时加载相应的HTML.J ...

  4. Spring MVC 属性文件读取注入到静态字段

    目录(?)[-] servlet-contextxml configproperties 示例属性 ConfigInfo 对应的配置bean 使用   在项目中,有些参数需要配置到属性文件xxx.pr ...

  5. Ubuntu12.04安装中文字体(转)

    1.在/usr/share/fonts/下,新建文件夹winFonts,如果没有fonts目录,就安装fontconfig软件(系统字体管理),再将win7字体msyh.ttf和msyhbd.ttf复 ...

  6. php支付接口,代付、感悟

    支付接口: 1.验证用户登录信息 2.验证参数.用加密串来匹配,开信息是否被篡改 3.如果有必要可以仿造购物城 建立购物车列表 4.建立和请求方的关联表 5.进行订单生成.支付流程.各种判断.验证. ...

  7. php文件复制

    <?php $dirname="shangchuan"; copydir($dirname."/uploads", $dirname."/hel ...

  8. Android——多线程编程练习题

    随便选择两个城市作为预选旅游目标.实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内),哪个先显示完毕,就决定去哪个城市.分别用Runnable接口和Thread类实 ...

  9. mysql5.6启动占用内存很大的解决方法

    vps的内存为512M,安装好nginx,php等启动起来,mysql死活启动不起来看了日志只看到对应pid被结束了,后跟踪看发现是内存不足被killed; 调整my.cnf 参数,重新配置(系统默认 ...

  10. JQ插件jquery.fn.extend与jquery.extend

    jQuery为开发插件提拱了两个方法,分别是: JavaScript代码 jQuery.fn.extend(object); jQuery.extend(object); jQuery.extend( ...