摘要: O(n^2) solution: Sweep public List<List<Integer>> getSkyline(int[][] buildings) { TreeSet<Integer> edgeSet = new TreeSet<>(); for(int[] building : bui 阅读全文
posted @ 2022-11-02 01:55 jdflyfly 阅读(15) 评论(0) 推荐(0) 编辑
摘要: import java.util.Random; public class Sorting { /** * For each element, compare with all the elements before it and swap position accordingly * https: 阅读全文
posted @ 2022-10-27 04:35 jdflyfly 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 思路:递归实现,注意翻转的规律,以左子树作为根,找到左子树最右边的节点作为原有right子树和根的父节点。 阅读全文
posted @ 2017-09-04 23:04 jdflyfly 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Leetcode: https://leetcode.com/problems/implement-trie-prefix-tree/ class Trie { Character curChar; boolean isEnd; Map<Character, Trie> children = new 阅读全文
posted @ 2014-10-19 17:14 jdflyfly 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 1.输入n个整数,输出其中最小的k个。 堆做法、quickSelect做法。堆做法代码:import java.util.ArrayList;import java.util.Comparator;import java.util.List;import java.util.PriorityQue... 阅读全文
posted @ 2014-09-30 09:59 jdflyfly 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 1. 给一个浮点数序列,取最大乘积连续子串的值,例如 -2.5,4,0,3,0.5,8,-1,则取出的最大乘积连续子串为3,0.5,8。2. 给定一个长度为N的整数数组,只允许用乘法,不能用除法,计算任意(N-1)个数的组合中乘积最大的一组,并写出算法的时间复杂度。3. 给定一个数组a[N],我们希... 阅读全文
posted @ 2014-09-25 22:32 jdflyfly 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 分解质因数求最大公约数求最小公倍数牛顿迭代求平方根分解质因数import java.util.ArrayList;import java.util.List;public class Solution { // 返回质因数分解 List getPrimeFactors(int n) { ... 阅读全文
posted @ 2014-09-17 17:11 jdflyfly 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 生产者消费者问题读者作家问题哲学家吃饭问题生产者消费者问题http://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem分别用锁、信号量、同步监视器模拟的例子。package thread;import java.util.Random;... 阅读全文
posted @ 2014-09-15 22:12 jdflyfly 阅读(308) 评论(1) 推荐(0) 编辑
摘要: 1. 无序数组求中位数 思路1:quick修改版的寻找kth元素,平均O(n),最长O(n^2)。 思路2:算法导论上worst case O(N)的算法,可见 这里2. 两个无序数组求中位数3. 两个有序数组求中位数 http://www.cnblogs.com/jdflyfly/p/381... 阅读全文
posted @ 2014-09-12 23:00 jdflyfly 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 图的表示:连接矩阵,连接链表。图的遍历:dfs(递归、非递归),bfs.连接矩阵下各种遍历:import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;impo... 阅读全文
posted @ 2014-09-11 16:30 jdflyfly 阅读(296) 评论(0) 推荐(0) 编辑