原创 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},

原创 置頂

寫這個主要是爲了儲存自己的學習練習的東西,方便查找,也是一個很好的備份。

原创 Lock on Static and non-static Methods

問題 Synchronized 關鍵字分別用在靜態和非靜態函數上, 其他setting相同, 多線程各自調用1000次, 哪個更快些? http://stackoverflow.com/questions/5654654/static-

原创 Java 知識點補充

1. thread and thread pool 2. super and this super(parameter list) in constructor調用父類裏constructor,只有super()則指向默認的那個。 thi

原创 Leetcode Blog Post Algorithms

package leetcode.blog; import java.util.ArrayList; import java.util.Arrays; public class LeetcodeBlog { // Q1 Find

原创 String Match & Observer & Decorator & A* Search Algorithm & RW Lock

String Match Rabin-Karp 原理很簡單,就是計算出pattern的hash值,然後截取text裏面的substring,計算hash值。一般O(m+n)。n是text長度,m是pattern長度。但是worst cas

原创 [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

原创 [RandomCoding]SameLeafNode

package RandomPractice; import util.*; public class SameLeafNode { public static boolean hasSameLeaf(BTNode root1, B

原创 [Random Coding] De/Serialization of Binary Search Tree

package RandomPractice; import java.util.ArrayList; import util.BTNode; public class DeSerializationBinarySearchTree

原创 Java代碼的執行順序

轉載自http://java-mzd.iteye.com/blog/838683 本文主要介紹以下兩塊內容的執行順序,熟悉的大蝦可以直接飄過。 DOG類 /** * DOG父類 */ public class Dog { pub

原创 Reservoir Sampling & Quickselect

Reservoir Sampling 適用於從很大的數據堆裏隨機取樣,一般適用於內存不足以裝入所有數據的情況。 從n個數據裏隨機取k個數 1. 用前k個數據組成一個reservoir 2. 從k+1開始,對於第i個元素,隨機產生一個1~

原创 [Random Coding]Topological Sorting

package random; import java.util.ArrayList; import java.util.HashSet; import java.util.Hashtable; import java.util.It

原创 知識點總結2 External Sorting, Bucket Sorting, and Radix Sorting

External Sorting Usage: Sort huge data with limited memory space. Main idea: Divide (in order to fit in the main memor

原创 一些知識點總結(HeapSort, MergeSort, QuickSort, PrefixTree, TopologicalSort)

HeapSort package RandomPractice; public class HeapSort { public static int heapSize = 0; public static void buildHe

原创 [Random Coding] De/Serialization Binary Tree

package RandomPractice; import java.util.ArrayList; import util.*; public class DeSerializationBinaryTree { public s