- 博客(171)
- 收藏
- 关注
原创 Lock on Static and non-static Methods
问题Synchronized 关键字分别用在静态和非静态函数上,其他setting相同, 多线程各自调用1000次, 哪个更快些?
2014-05-16 10:20:35
767
原创 String Match & Observer & Decorator & A* Search Algorithm & RW Lock
String MatchRabin-Karp原理很简单,就是计算出pattern的hash值,然后截取text里面的substring,计算hash值。一般O(m+n)。n是text长度,m是pattern长度。但是worst case是O(mn)。当有多个pattern的时候比较好用,因为一个hashtable可以存多个hash值,一起挨个比较。该方法多用于判断抄袭。Aho-Cora
2014-03-21 14:34:13
803
原创 Java 知识点补充
thread and thread poolsuper()this() in constructorstatic blockListIteratorImplementation of Map interfaceHashMapHashtableTreeMapEnumMapImplementation of Set interfaceHashSetTre
2014-03-15 03:41:11
597
转载 Java代码的执行顺序
转载自http://java-mzd.iteye.com/blog/838683本文主要介绍以下两块内容的执行顺序,熟悉的大虾可以直接飘过。 一。JAVA中执行顺序静态块块构造器父类构造器 二。JAVA中赋值顺序 静态块直接赋值 块直接赋值 父类继承的属性已赋值 静态变量声明时赋值 成员变量声明
2014-03-14 22:41:21
822
原创 [Leetcode] Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes
2014-03-14 01:58:41
628
原创 [Random Coding] De/Serialization of Binary Search Tree
package RandomPractice;import java.util.ArrayList;import util.BTNode;public class DeSerializationBinarySearchTree { public static void serialize(BTNode root, ArrayList list){ if(root == null)
2014-03-08 05:55:40
682
原创 [Random Coding] De/Serialization Binary Tree
package RandomPractice;import java.util.ArrayList;import util.*;public class DeSerializationBinaryTree { public static void serialize(BTNode root, ArrayList list){ if(root == null) list.add
2014-03-08 05:48:30
576
原创 [Random Coding] Tree Iterator
package RandomPractice;import java.util.NoSuchElementException;import util.*;public class TreeIterator { private BTNode next; public TreeIterator(BTNode root){ next = root; if(next == null)
2014-03-08 05:29:08
567
原创 [RandomCoding]SameLeafNode
package RandomPractice;import util.*;public class SameLeafNode { public static boolean hasSameLeaf(BTNode root1, BTNode root2){ if(root1 == null && root2 == null) return true; if(root1 ==
2014-03-08 05:04:03
504
原创 [Random Coding]Topological Sorting
To be continued.package leetcode.blog;import java.util.ArrayList;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.List;public class TopoSort {
2014-02-19 06:15:05
545
原创 [Random Coding]StackWithMin
import java.util.Stack;public class StackWithMin { Stack stack = new Stack(); Stack min = new Stack(); public void push(Integer val){ stack.push(val); if(min.isEmpty() || val <= min.peek())
2014-02-19 05:39:11
521
原创 [Random Coding]QueueWithMin
import java.util.LinkedList;import java.util.Queue;public class QueueWithMin { Queue queue = new LinkedList(); LinkedList min = new LinkedList(); public void offer(Integer val){ queue.offer(va
2014-02-19 05:36:12
532
原创 Decision Tree & Threaded Binary Tree & Information Entropy
Decision TreeA tree-like graph or model of decisions and their possible consequences.Threaded Binary Tree如果right child是null pointer就指向inorder successor如果left child是null pointer就指向inorder p
2014-02-19 05:26:20
704
原创 Reservoir Sampling & Quickselect
Reservoir Sampling适用于从很大的数据堆里随机取样,一般适用于内存不足以装入所有数据的情况。从n个数据里随机取k个数1. 用前k个数据组成一个reservoir2. 从k+1开始,对于第i个元素,随机产生一个1~i之间的数j,如果j证明tips每次循环,reservoir里第j个(jQuickselectO(n),每次都去掉一
2014-02-19 04:53:56
649
原创 Leetcode Blog Post Algorithms
package leetcode.blog;import java.util.ArrayList;import java.util.Arrays;public class LeetcodeBlog { // Q1 Find Intersection of two Sorted Arrays // if either A or B 's length is too big, try t
2014-01-18 04:52:19
868
原创 知识点总结2 External Sorting, Bucket Sorting, and Radix Sorting
External SortingUsage: Sort huge data with limited memory space.Main idea: Divide (in order to fit in the main memory), thenmerge together.One example from Wiki:Sort 900 MB data with 100 MB RA
2014-01-11 04:00:19
1068
原创 一些知识点总结(HeapSort, MergeSort, QuickSort, PrefixTree, TopologicalSort)
HeapSortpackage RandomPractice;public class HeapSort { public static int heapSize = 0; public static void buildHeap(int[] A){ heapSize = A.length; for(int i = A.length / 2 - 1; i >= 0; i--)
2014-01-01 02:37:18
1212
原创 Leetcode: Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",
2013-12-31 03:45:44
615
原创 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.算斜率的时候一定注意要格式转换,integer-〉double/** * Definition for a point. * class Point { * int x; *
2013-12-31 03:14:21
584
原创 Java 不同版本更新总结
面试时候虽没有被问到,但是感觉在相关问题上丢了面试分,在此总结一下。参考 Referencehttp://pwosboy.iteye.com/blog/118756http://hanhg.iteye.com/blog/291956http://pengcqu.iteye.com/blog/499749Java 1.51. Generic在之前版本,如果声明
2013-11-27 06:00:52
703
原创 Leetcode: Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; *
2013-11-14 04:58:39
1467
原创 [Random Coding]Interval Related Questions
import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.PriorityQueue;public class WeightedInterval { public static class Interval { int start; i
2013-11-11 11:29:52
786
原创 Leetcode: LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:get and set.get(key) - Get the value (will always be positive) of the key if t
2013-11-11 10:46:43
2519
原创 Leetcode: Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution is tri
2013-11-11 10:46:03
724
原创 Leetcode: Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution is triv
2013-11-11 10:45:12
844
原创 Leetcode: Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to {1,4
2013-11-11 10:44:24
820
原创 Leetcode: Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list.
2013-11-11 10:43:31
848
原创 Leetcode: Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; *
2013-11-11 10:41:53
805
原创 Word Break II
// DFS + Memorization public ArrayList wordBreak(String s, Set dict) { // Note: The Solution object is instantiated only once and is reused by // each test case. // min and max length of words
2013-10-09 11:49:44
2032
原创 Word Break
/* * Given a string s and a dictionary of words dict, * determine if s can be segmented into a space-separated sequence * of one or more dictionary words. * * For example, given * s = "le
2013-10-09 09:58:18
822
原创 Copy List with Random Pointer
/* * A linked list is given * such that each node contains an additional random pointer * which could point to any node in the list or null. * * Return a deep copy of the list. */public
2013-10-09 09:57:32
747
原创 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using
2013-10-04 01:09:55
1520
原创 Leetcode Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Could you implement it without using extra memory? public int singleNumber(int[] A) {
2013-10-03 09:53:52
742
原创 Leetcode: Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on
2013-10-02 12:12:59
3346
2
转载 Gas Station
出自 http://blog.youkuaiyun.com/lbyxiafei/article/details/12183461There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlim
2013-10-02 10:20:29
818
原创 CloneGraph
Clone an undirected graph. Each node in the graph contains a label and a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled from 0 to N - 1, where N is the total nodes
2013-09-28 03:33:57
685
原创 Leetcode: Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X O
2013-07-16 11:39:20
693
原创 Leetcode: Sum Root to Leaf Number
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.Find the total sum
2013-07-16 11:09:04
566
原创 Leetcode: Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3,
2013-07-16 10:55:28
643
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人