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. 【设计模式】行为型04迭代器模式(Iterator Pattern)

    学习地址:http://www.runoob.com/design-pattern/iterator-pattern.html 迭代器模式,简单来说就是通过迭代的方式对集合进行遍历,在集合的学习中也一 ...

  2. 阅读HashMap——jdk7时遇到的问题记录

    今天看hashMapJDK7版,水很深,看的也痛苦~推一个博主:http://www.cnblogs.com/xrq730/ 看了源码,才发现自己基础真的很薄弱,虽然当初也是下了很多的经历,但是毕竟大 ...

  3. bitmap-如何判断某个整数是否存在40亿个整数中?

    有这样一道面试题:现有40亿个整数,如果再给定一个新的整数,怎么判断这个整数是否在这40亿个整数中? 你可能首先会想到用一个set存储,那个新数只需判断是否在set中.但是如果用set存储的话,如果一 ...

  4. vscode左边侧边栏字体的大小

    相信很多小伙伴们都会在用vscode的时候,当屏幕大小发生变化的时候,你可能会觉得左边的字体太小了,我也遇到了这样的问题,百度也没有找到解决办法,自己摸索了几天,发现可以通过ctrl+shift+ + ...

  5. vue随笔

    1.vue基础 Vue 是一个mvvm 的渐进式框架.Angular 是一个mvc的.所以vue的重点更偏向于mv 他的使用方式 大家会发现里面带有大量的$的属性. 学习vue的指令 V-for  用 ...

  6. 通过CDN引入jQuery的几种方式

    百度 CDN <head> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" ...

  7. restapi(0)- 平台数据维护,写在前面

    在云计算的推动下,软件系统发展趋于平台化.云平台系统一般都是分布式的集群系统,采用大数据技术.在这方面akka提供了比较完整的开发技术支持.我在上一个系列有关CQRS的博客中按照实际应用的要求对akk ...

  8. cocopods新建或者更新远端库主要操作步骤

    1.搭建远程仓库(私有或者公有项目): 2.使用sourceTree拉去远程仓库: 3.打开拉去的项目仓库Finder,构建pod lib项目:pod lib create AFNetworking( ...

  9. JsonUtil(基于Jackson的实现)

    JsonUtil(基于Jackson的实现) 前言: 其实,我一直想写一个有关Util的系列. 其中有四个原因: Util包作为项目的重要组成,是几乎每个项目不可或缺的一部分.并且Util包的Util ...

  10. EnjoyingSoft之Mule ESB开发教程系列第五篇:控制消息的流向-数据路由

    目录 1. 使用场景 2. 基于消息头的路由 2.1 使用JSON提交订单的消息 2.2 使用XML提交订单的消息 2.3 使用Choice组件判断订单格式 3. 基于消息内容的路由 4. 其他控制流 ...