- 博客(421)
- 资源 (7)
- 收藏
- 关注
原创 (转) External Sort
我觉得这个是讲External Sort的文章中,最容易看懂的文章http://faculty.simpson.edu/lydia.sinapova/www/cmsc250/LN250_Weiss/L17-ExternalSortEX1.htmCC as below:CmSc 250 Intro to AlgorithmsEx
2015-12-15 04:32:25 2845
原创 Java菜鸟入门(21) Merge K sorted List
假设输入是K个iterator, 如何来merge这K个iterator of Integer,使得输出是 List?1. 类似Merge K sorted List普通题的思路,使用PriorityQueue(or, Heap2. 使用一个wrapper来把current Integer value和它的相关的Iterator给捆绑打包。这样做的原因是,每次使用了iterator.nex
2015-12-14 18:00:35 1316
原创 Java菜鸟入门(20) Producer Consumer经典代码
来自oracle官网 https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Condition.html class BoundedBuffer { final Lock lock = new ReentrantLock(); final Condition notFull = lock.newC
2015-12-13 07:32:23 1642
原创 LeeCode(149) Max Points on a Line
题目如下:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析如下:思路比较直接,对其中某一个点i, 找到点i和剩下的所有n - 1个点构成的斜率。如果在这n - 1个斜率中,能够找到这样一个值,这个出现次数最多,那么就可以认为,
2015-12-11 12:19:51 883
原创 LeetCode(269) Alien Dictionary (Java)
题目如下:There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of words from the dictionary, where words are sorted lexicog
2015-11-25 18:58:18 4443
原创 JAVA菜鸟入门 (19) inner calss: static v.s. non-static在main中被实例化时的区别
1. 首先, class中的class粗略地分成2类, static v.s non-static."Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are simply called static nested clas
2015-10-29 16:53:26 1157
原创 LintCode Number of Airplanes in the Sky(Java)
题目如下:Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most?Have you met this question in a real interview? YesExampleFor interval li
2015-10-12 02:07:43 2323
原创 How to first sort by one attribute, if equal, then sort by another attribute.
这个小代码来demo一下,如何来按照两个字段进行sort。 场景1有一个list of classes,每个class中的attribute 1是String name, attribute 2是 Int age。现在假设需求是先按照name 字母顺序升序排序,加入两个人同名同姓,再按照age升序排序。 在这样的场景下,就需要使用comparator去对2个字段进行排序。场
2015-09-28 13:12:21 629
原创 Trie相关的一些题目[draft]
关于trie的定义和图形请先看这里的简短描述。下面列出它相关的一些基本操作。1. build a trie这是基本操作,建立一个trie,add a word, search for that word, 正好有道题目在Leetcode上.class TrieNode { // Initialize your data structure here. char elem
2015-09-27 15:15:38 1032
原创 LeetCode 分类整理(01) DFS 草稿
subset// solution 2 version B// a slightly different version from version A.// make a slight optimization while doing right shift.public class Solution { public List> subsets
2015-08-31 15:46:44 1009
原创 LeetCode(078) Subsets (Java)
题目如下:Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For exampl
2015-07-02 13:54:17 1027
原创 JAVA菜鸟入门(18) Set的Iterator
1. 使用iterator遍历Set中元素public class SetIteratorDemo { public static void main(String[] args) { HashSet objectSet = new HashSet(); objectSet.add("white"); objectSet.add("white"); objectSet.add
2015-06-23 15:03:43 3565
原创 JAVA菜鸟入门(17) 有排序的TreeSet和无排序的HashSet, LinkedHashSet
General-Purpose Set ImplementationsThere are three general-purpose Set implementations — HashSet, TreeSet, and LinkedHashSet. Which of these three to use is generally straightforward.HashSet i
2015-06-22 01:51:42 771
原创 JAVA菜鸟入门(16) callback函数
Java中的callback函数, template:interface CallBack { void methodToCallBack();}class CallBackImpl implements CallBack { public void methodToCallBack() { System.out.println("I've been ca
2015-05-21 01:24:56 1071
原创 SumOfNestedList
get sum of NestedList是一道非常有名非常高频的的电面题/** * Given a nested list of integers, returns the sum of all integers in the list weighted by their depth * For example, given the list {{1,1},2,{1,1}} the
2015-05-18 15:30:54 1009
原创 JAVA菜鸟入门(15) static method/ field与normal method/field的相互调用关系
1. normal method uses static field => finepublic class StaticFieldDemo { public static int staticVar; public int instanceVar; /* * test1 normal method uses static field */ public void No
2015-05-18 14:44:43 1694
原创 JAVA菜鸟入门(14) Anonymous Class 和 final variable
Anonymous Class在使用外面的local variable的时候,要declare为final,否则会有compiler error.import javax.swing.JButton;import javax.swing.JTextField;public class HelloWorldAnonymousClasses { public HelloWorldAno
2015-05-09 06:51:07 1096
原创 JAVA菜鸟入门(13) outer class与inner class的之间能互相使用field或者method吗?
Nested classes are divided into two categories: static and non-static. 1. Nested classes that are declared static are called static nested classes. 2. Non-static nested classes are called inner cl
2015-05-01 04:44:46 2750
原创 JAVA菜鸟入门(12) reference variable是气球的线 +JVM中怎么实现
1 如果variable是primitive,那就拷贝原来变量的值到新变量。2 如果variable是object referece, 那就拷贝原来reference的值到新的变量,所以就有2个reference varibal指向了相同的object.eg. // Before the method callObject x = null;// Start of method c
2015-04-28 23:42:42 4669
原创 JAVA菜鸟入门(11) 基本类型
一. 基本类型Java 基础数据类型byte (number, 1 byte)short (number, 2 bytes)int (number, 4 bytes)long (number, 8 bytes)float (float number, 4 bytes)double (float number, 8 bytes)char (a characte
2015-04-26 01:11:03 1131
原创 JAVA菜鸟入门(10) 类初始化, 字符串比较equals() v.s. ==, Casting, ArrayList注意
一. 类的初始化第一种更推荐, 可以简化或者省略构造函数,代码简洁第二种 public class WeatherForecast{private String skies = "";private int high = 0;private int low = 0;public void setSkies(
2015-04-26 00:50:09 841
原创 JAVA菜鸟入门(9) Java打印一维数组,二维数组
一 打印list中的元素0 JAVA风格的最简做法import java.util.List;...List l = new ArrayList(3);System.out.println(l);1 JAVA风格的做法import java.util.Arrays;import java.util.List;import java.util.ArrayList;...
2015-04-26 00:39:24 15959 1
原创 JAVA菜鸟入门(8) Java的Final关键字
java final 和C++的const功能类似,用来表达常量,还能用在class或者method上,提供不同的用法。1. Java Final Variable Once a final variable has been assigned, it always contains the same value.但是 static final和private final是
2015-04-26 00:32:37 1232
原创 LeetCode(119) Pascal's Triangle II (Java)
题目如下:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?我的代码:
2015-04-20 10:01:28 2590
原创 LeetCode(188) Best Time to Buy and Sell Stock IV (Java)
题目如下:Best Time to Buy and Sell Stock Total Accepted: 43912 Total Submissions: 135635 My Submissions Question Solution Say you have an array for which the ith element is the price of a given stock
2015-04-19 15:45:27 7382
原创 LeetCode(123) Best Time to Buy and Sell Stock III (Java)
题目如下:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:Y
2015-04-19 13:20:26 1521
原创 LeetCode(122) Best Time to Buy and Sell Stock II (Java)
题目如下:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie,
2015-04-19 13:18:34 1532
原创 LeetCode(121) Best Time to Buy and Sell Stock (Java)
题目如下:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the
2015-04-19 13:15:43 1786
原创 LeetCode(045) Jump Game II (Java)
题目如下:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your
2015-04-13 15:00:17 1318
原创 LeetCode(055) Jump Game (Java)
题目如下:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Dete
2015-04-13 13:43:48 572
原创 LeetCode(080) Remove Duplicates from Sorted Array II (Java)
题目如下:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now
2015-04-13 13:18:27 542
原创 LeetCode(074) Search a 2D Matrix (Java)
题目如下:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of
2015-04-13 12:37:58 1171
原创 LeetCode(034) Search For a Range (Java)
题目如下:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not
2015-04-13 10:44:31 1054
原创 LeetCode(048) Rotate Image
题目如下:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?分析如下:首先沿着对角线(左上->右下)方向翻折,然后沿着中轴方向翻折。
2015-04-13 04:06:41 494
原创 LeetCode(035) Search Insert Position (Java)
题目如下:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the
2015-04-13 01:57:35 614
原创 LeetCode(073) Set Matrix Zeroes (Java)
题目如下:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably
2015-04-13 01:26:49 667
原创 LeetCode(118) Pascal's Triangle (Java)
题目如下:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]我的代码:
2015-04-12 15:48:08 1761
原创 LeetCode(088) Merge Sorted Array(Java)
题目如下:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional element
2015-04-12 14:25:10 726
原创 LeetCode(001) Two Sum (Java)
题目如下:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the targ
2015-04-12 07:12:48 732
原创 LeetCode(026) Remove Duplicates from Sorted Array (Java)
题目如下:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in pla
2015-04-12 03:13:57 682
数据挖掘--概念.模型.方法和算法
2009-09-20
机器学习 Tom Mitchell 中文版
2009-09-20
机器学习英文版Machine Learning(Mitchell)(下)
2009-09-14
机器学习英文版Machine Learning(Mitchell)(中)
2009-09-14
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人