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. Windows 10下Chrome不能启动的问题

    不能启动了 Chrome突然不能启动了,点击图标也没反应,打开任务管理器,发现点击图标后,Google Ghrome短暂地出现,随即消失. 如何解决? 解决方案 打开安装目录: C:\Program ...

  2. Think Python - Chapter 18 - Inheritance

    In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...

  3. jbrowse 的配置与使用gff, vcf, fa, bed, bam

    1,jbrowse 是什么东西 ? JBrowse is a genome browser with a fully dynamic AJAX interface, being developed a ...

  4. SAP 增强说明

    转自http://blog.csdn.net/lyb_yt/article/details/8177974 (一)什么是增强(Enhancement)? 简单地说,增强就是ERP系统中标准程序的出口, ...

  5. 权限分配界面 纯手工 仅用到bootstrap的架构 以及 c标签

    <div class="form-group">        <div class="row">         <label ...

  6. JavaWeb学习记录(三)——网页中文编码问题

    方法一: public void doGet(HttpServletRequest request, HttpServletResponse response)            throws S ...

  7. timus 1033 Labyrinth(BFS)

    Labyrinth Time limit: 1.0 secondMemory limit: 64 MB Administration of the labyrinth has decided to s ...

  8. HDU-1561 The more, The Better (树形DP+分组背包)

    题目大意:给出一片森林,总共有n个点,并且都有权值.从中选出m个,使权值和最大.其中,选某个节点之前必须先选其父节点. 题目分析:给所有的树都加一个共同的权值为0的根节点,使森林变成一棵树.定义状态d ...

  9. poj2240 最短路判环

    题意:与poj1680一样,有不同的换钱渠道,可以完成特定两种货币的交换,并且有汇率,只不过此题是单向边,然后问是否能使财富增加 与poj1680一样,建图之后直接spfa判增值的环即可 #inclu ...

  10. Codeforces Round #339 Div.2 C - Peter and Snow Blower

    Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. A ...