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. Mybatis_One

    Mabatis的概述 JavaEE开发是分层的:表现层 业务层 持久层 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互的方法;另一种定义认为,框架是可被应用 ...

  2. 干货!Git 如何使用多个托管平台管理代码

    考虑到github不能免费创建私有仓库原因,最近开始在使用码云托管项目,这样避免了连接数据库的用户密码等信息直接暴露在公共仓库中.今天突然想到一个点,就是能不能同时把代码推送到github和码云上呢? ...

  3. 【需要重新维护】Redis笔记20170811视频

    很多内容都是抄的,个人记录 1.windows下初见 安装 进入目录 修改配置文件(暂时使用默认,未配置环境变量) 目录下:redis-server.exe启动服务 新建命令提示符,目录下,redis ...

  4. 【转载】tomcat原理

    转载地址:https://blog.csdn.net/u014795347/article/details/52328221?locationNum=2&fps=1 以下代码纯属本人复制,而且 ...

  5. 最方便分布式爬虫管理框架--Gerapy

    Gerapy 是一款国人开发的爬虫管理软件(有中文界面) 是一个管理爬虫项目的可视化工具,把项目部署到管理的操作全部变为交互式,实现批量部署,更方便控制.管理.实时查看结果. gerapy和scrap ...

  6. Visual Studio模板代码注释小技巧分享

    在日常开发过程中,难免有这样一种需求:就是你所建的每一个类文件或者接口文件都需要标注下作者姓名以及类的用途.如果我们每次创建文件的时候都需要写一遍这些信息是很烦神的.还好Visual Studio给我 ...

  7. python面试题(-)可变数据类型与不可变数据类型

    python3中有六个标准的数据类型:number(数字型).string(字符串型).list(列表).type(元祖).dictionary(字典).set(集合),其中不可变类型三个:numbe ...

  8. 机器学习经典算法之Apriori

    一. 搞懂关联规则中的几个概念 关联规则这个概念,最早是由 Agrawal 等人在 1993 年提出的.在 1994 年 Agrawal 等人又提出了基于关联规则的 Apriori 算法,至今 Apr ...

  9. web交互方式---ajax

    知识不怕旧,关键在于在旧知识的基础上不断创新与提高! 引入一个问题:打开一个浏览器,在地址栏输入一个网址,按下 enter 键到看到整个页面,中间都经历了哪些事情? 这是一个前端的面试题,相信很多朋友 ...

  10. 【测试-测试心得】测试发现BUG后,怎么定位问题?

    一.判断前后端 Safari中可以右键,选择“检查元素”,再选择“网络”同样可以抓取到http请求,如图 怎么区分是前端错误还是后端错误? 1.在开发者工具中,如果console中有报错,则表示前端代 ...