1

2 218 The Skyline Problem     最大堆   遍历节点

    public List<int[]> getSkyline(int[][] buildings) {
List<int[]> res = new ArrayList<>();
List<int[]> point = new ArrayList<>();
for (int i = 0; i < buildings.length; i++)
{
point.add(new int[]{buildings[i][0], buildings[i][2]});
point.add(new int[]{buildings[i][1], -buildings[i][2]});
}
Collections.sort(point, (a,b)-> {
if (a[0] != b[0]) return a[0] - b[0];
return b[1] - a[1];});
PriorityQueue<Integer> maxheap = new PriorityQueue<>((a,b)->(b - a));
int cur = 0, pre = 0;
for (int i = 0; i < point.size(); i++)
{
int[] b = point.get(i);
if (b[1] > 0)
{
maxheap.add(b[1]);
cur = maxheap.peek();
}
else
{
maxheap.remove(-b[1]);
cur = maxheap.peek() == null ? 0 : maxheap.peek();
}
if (pre != cur)
{
res.add(new int[]{b[0], cur});
pre = cur;
}
}
return res;
}

3  241 Different Ways to Add Parentheses   找符号,分开

    public List<Integer> diffWaysToCompute(String input) {
List<Integer> res = new LinkedList<>();
for (int i = 0; i < input.length(); i++)
{
char c = input.charAt(i);
if (c == '+' || c == '-' || c == '*')
{
String a = input.substring(0, i);
String b = input.substring(i+1);
List<Integer> a1 = diffWaysToCompute(a);
List<Integer> b1 = diffWaysToCompute(b);
for (int x : a1)
{
for (int y : b1)
{
if (c == '+')
{
res.add(x + y);
}
else if (c == '-')
{
res.add(x - y);
}
else if (c == '*')
{
res.add(x * y);
}
}
}
}
}
if (res.size() == 0) res.add(Integer.valueOf(input));
return res;
}

Divide and Conquer的更多相关文章

  1. [LeetCode] 236. Lowest Common Ancestor of a Binary Tree_ Medium tag: DFS, Divide and conquer

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  2. [LeetCode] 系统刷题4_Binary Tree & Divide and Conquer

    参考[LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal 可以对binary tree进行遍历. 此处说明Divi ...

  3. [LeetCode] 124. Binary Tree Maximum Path Sum_ Hard tag: DFS recursive, Divide and conquer

    Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...

  4. 算法与数据结构基础 - 分治法(Divide and Conquer)

    分治法基础 分治法(Divide and Conquer)顾名思义,思想核心是将问题拆分为子问题,对子问题求解.最终合并结果,分治法用伪代码表示如下: function f(input x size ...

  5. 算法上机题目mergesort,priority queue,Quicksort,divide and conquer

    1.Implement exercise 2.3-7. 2. Implement priority queue. 3. Implement Quicksort and answer the follo ...

  6. 【LeetCode】分治法 divide and conquer (共17题)

    链接:https://leetcode.com/tag/divide-and-conquer/ [4]Median of Two Sorted Arrays [23]Merge k Sorted Li ...

  7. The Divide and Conquer Approach - 归并排序

    The divide and conquer approach - 归并排序 归并排序所应用的理论思想叫做分治法. 分治法的思想是: 将问题分解为若干个规模较小,并且类似于原问题的子问题, 然后递归( ...

  8. [算法]分治算法(Divide and Conquer)

    转载请注明:http://www.cnblogs.com/StartoverX/p/4575744.html 分治算法 在计算机科学中,分治法是建基于多项分支递归的一种很重要的算法范式.字面上的解释是 ...

  9. Divide and Conquer.(Merge Sort) by sixleaves

    algo-C1-Introductionhtml, body {overflow-x: initial !important;}html { font-size: 14px; }body { marg ...

  10. 分治法 - Divide and Conquer

    在计算机科学中,分治法是一种很重要的算法.分治法即『分而治之』,把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最后子问题可以简单的直接求解,原问题的解即子问题的 ...

随机推荐

  1. python 方法无法在线程中使用(附python获取网络流量)

    在python中,定义一个方法,直接调用可以,但是创建一个线程来调用就可能导致失败.这种现象多出现在使用com对象进行系统操作时,而且是以线程的形式调用. 异常提示如下:syntax error.WM ...

  2. 远程控制卡配置和RAID基本知识

    一.远程控制卡配置(戴尔R710)ctrl+eLAN Parameters ==>>远程连接IP地址配置LAN User Configuration ==>>远程连接账号密码配 ...

  3. selenium工作原理详解

    selenium简介 Selenium是一个用于Web应用程序自动化测试工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11), ...

  4. spring源码解析之IOC容器(四)——属性注入

    上一篇跟踪了bean的创建过程,接下来,我们继续跟踪bean的属性填充的过程.先回到doCreateBean方法,代码如下: protected Object doCreateBean(final S ...

  5. python Trojan 模块(我忘记几了)—— 通信隧道建立

    0X01 SSH的建立  我想,第一步先实现简单的ssh通信再说,类似其他那种高端的C&C将逐步研究 对于ssh,python有个module叫paramiko,对没错看起来像日语单词 The ...

  6. Elasticsearch的使用

    我这边是以elasticsearch-2.4.3为例:引入maven <dependency> <groupId>org.elasticsearch.client</gr ...

  7. spring cloud 系列第2篇 —— eureka 高可用注册中心的搭建 (F版本)

    源码仓库地址:https://github.com/heibaiying/spring-samples-for-all 一.项目结构 eureka-server为服务注册中心,负责服务的管理: eur ...

  8. 【分页工具-spring boot】Mybatis PageHelper 集成Spring boot

    官方文档:https://github.com/pagehelper/pagehelper-spring-boot 1.引入包,测试过以下版本兼容性还是比较好的 <!--Mybatis-Spri ...

  9. package.json 详解

    使用package.json  属性说明 name - 包名. version - 包的版本号. description - 包的描述. homepage - 包的官网 url . author - ...

  10. 机器学习经典算法之EM

    一.简介 EM 的英文是 Expectation Maximization,所以 EM 算法也叫最大期望算法. 我们先看一个简单的场景:假设你炒了一份菜,想要把它平均分到两个碟子里,该怎么分? 很少有 ...