自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(133)
  • 资源 (3)
  • 收藏
  • 关注

转载 面试准备汇总

准备经验总结:http://mitbbskr.com/article_t/JobHunting/32516109.htmlhttp://blog.zhuhuang.com/2011/12/apply-google-microsoft-intern/http://www.huaren.us/dispbbs.asp?boardid=373&id=1175952&page=3&sta

2013-12-27 00:03:37 1972 2

转载 Effectiv Java 读书笔记 Item 1

考虑用静态工厂方法代替构造器我们有两种常见的方法获得一个类的实例.静态工厂方法的优点:优势1. 静态工厂方法的名称,因此比构造器更准确地描述返回的实例。对比:构造器的命名都一致,一个类只能有一个指定签名的构造器。当一个类需要提供多个构造器时,通常只是通过不同的形参类型的顺序加以区分,但其函数名还是相同的,无法提供较高的区分度。结论:当一个类需要多个带有相

2015-05-28 04:03:48 691

原创 Singleton

// Lazy initialization, not good for currencypublic class SingletonDemo { private static SingletonDemo instance = null; private SingletonDemo() {} public static synchronized SingletonDemo getInst

2014-11-12 04:39:33 553

原创 Leetcode wild card matching

public class Solution { private int[][] dp; public boolean isMatch(String s, String p) { if (s == null || p == null) { return false; } dp = ne

2014-11-12 03:29:58 691

转载 Move all zeroes to end of array

Move all zeroes to end of arrayGiven an array of random numbers, Push all the zero’s of a given array to the end of the array. For example, if the given arrays is {1, 9, 8, 4, 0, 0, 2, 7, 0,

2014-11-09 10:53:16 775

转载 使用 trie tree 实现 auto-completion

In-Memory TrieTries are specialized data structures where a word can be stored as a sequence of characters. Reading the word involves traversing down the branch of the tree. At each node, the po

2014-10-20 06:15:16 793

转载 Rotating an array in place

The answer is of course, yes. This is a trick so important that it becomes one of the frequently asked interview questions. An in-depth discussion is in Programming Pearls, one of the must-read book

2014-10-19 05:22:52 576

转载 分布式中 CAP BASE ACID 理解

概念理解(CAP,BASE, ACID)CAPCAP:  Consistency, Availability, Partition-tolerance强一致性(Consistency)。系统在执行过某项操作后仍然处于一致的状态。在分布式系统中,更新操作执行成功后所有的用户都应该读取到最新的值,这样的系统被认为具有强一致性。可用性(Availability)。

2014-10-14 10:26:37 772

转载 漫谈事务与分布式事务(4)- 最终一致性

在上一篇文章里忽略了一点。 CAP 定理有一个缺陷,这个缺陷可以帮助我们“部分”摆脱 分布式困境。 总的来说,CAP 定理本身是完备的,但它并没有描述一个分布式系统何时产生分区,以及分区会持续多长时间。理论其实只限制:在分区发生的 一瞬间,系统只能在一致性(C)和可用性(A)之间二选一。 因此,分布式系统完全可以在没有出现分区时保证 C 和 A,而在

2014-10-14 10:25:56 681

转载 Distributed system - BASE

BASE (Like the Opposite of ACID, Get It?)You'll occasionally hear or read of the acronym BASE. This acronym captures one way of thinking about "good enough":Basically available means that sm

2014-10-14 10:24:32 587

转载 分布式系统中的CAP理论

CAP理论被很多人拿来作为分布式系统设计的金律,然而感觉大家对CAP这三个属性的认识却存在不少误区。从CAP的证明中可以看出来,这个理论的成立是需要很明确的对C、A、P三个概念进行界定的前提下的。在本文中笔者希望可以对论文和一些参考资料进行总结并附带一些思考。一、什么是CAP理论CAP原本是一个猜想,2000年PODC大会的时候大牛Brewer提出的,他认为在设计一个大规模可扩放的网络

2014-10-14 09:53:35 691

转载 Distributed system - CAP

The CAP/Brewer ConjectureIt is commonly desirable for distributed systems to exhbit Consistency, Availability, and Partition tolerance.By consistency we mean that all participating systems sha

2014-10-14 09:52:54 788

原创 Distributed System 笔记 - Consistency 和 Data replication

学习资源:CMU 15440 Lecture note: http://www.andrew.cmu.edu/course/15-440-f14/index/lecture_index.html分布式系统原理与范型, chap6

2014-10-14 03:05:29 940

转载 避免dead lock的方法

在有些情况下死锁是可以避免的。本文将展示三种用于避免死锁的技术:加锁顺序加锁时限死锁检测加锁顺序当多个线程需要相同的一些锁,但是按照不同的顺序加锁,死锁就很容易发生。如果能确保所有的线程都是按照相同的顺序获得锁,那么死锁就不会发生。看下面这个例子:Thread 1: lock A lock BThread 2: wait for A

2014-10-13 10:27:09 1683

转载 2PL - 两阶段锁

8.6 两段锁协议    所谓两段锁协议是指所有事务必须分两个阶段对数据项加锁和解锁。    ·在对任何数据进行读、写操作之前,首先要申请并获得对该数据的封锁;    ·在释放一个封锁之后,事务不再申请和获得任何其他封锁。    所谓“两段”锁的含义是,事务分为两个阶段,第一阶段是获得封锁,也称为扩展阶段。在这阶段,事务可以申请获得任何数据项上的任何类型的锁,但是不能释放任何锁。第

2014-10-13 10:17:59 3423

原创 Distributed System 笔记 - Synchronization 和 ACID

学习资源:CMU 15440 Lecture note: http://www.andrew.cmu.edu/course/15-440-f14/applications/ln/lecture7.html

2014-10-13 03:17:43 954

转载 表达式树的简单实现

表达式树是树结构的一个经典应用,常用于编译器的设计。在表达式树中,叶子通常是常数值或者变量名,统称为操作数(operands)。而其他非叶子结点则包含各种操作符(operators)。在不同的词法解析中,表达式树的分支设计也不同。对于简单的诸如表达式求解而言,表达式树往往采用二叉树。这是因为每一个操作符正好对应两个操作数。而在包含一元操作符(e.g自增自减操作符)或三元操作

2014-10-10 23:54:00 4060

转载 逆波兰式与表达式求解

一、历史逆波兰式表示法(Reverse Polish Notation, RPN)可以看作波兰表示法(PN)的一种逆向表示。后者最初由波兰数学家Jan Lukasiewicz在1920年提出,由此得名。在波兰表示法中,每个操作符均在相应的操作数之前,这也是牛逼的Lisp采用的表达式风格。与此相对的,逆波兰式中,每个操作符都在其操作数之后,由此也得名“后缀表示法(Postfix)”

2014-10-10 23:53:10 1033

转载 数据结构之红黑树

1. 简介红黑树是一种自平衡二叉查找树。它的统计性能要好于平衡二叉树(AVL树),因此,红黑树在很多地方都有应用。在C++ STL中,很多部分(目前包括set, multiset, map, multimap)应用了红黑树的变体(SGI STL中的红黑树有一些变化,这些修改提供了更好的性能,以及对set操作的支持)。它是复杂的,但它的操作有着良好的最坏情况运行时间,并且在实践中是高

2014-10-10 23:50:17 502

转载 Example of Unix commands implemented in Java

I created some illustrative and simple implementations of common Unix commands. For those who are familiar with Unix-like systems them make easier to understand Java. For those who are familiar with J

2014-10-10 00:29:00 542

转载 Java 读写锁的简单实现

原文链接 作者:Jakob Jenkov 译者:微凉 校对:丁一相比Java中的锁(Locks in Java)里Lock实现,读写锁更复杂一些。假设你的程序中涉及到对一些共享资源的读和写操作,且写操作没有读操作那么频繁。在没有写操作的时候,两个线程同时读一个资源没有任何问题,所以应该允许多个线程能在同时读取共享资源。但是如果有一个线程想去写这些共享资源,就不应该再有其它线程对该资源进行读

2014-10-09 11:17:45 891

转载 ThreadLocal的正确用法

用法一:在关联数据类中创建private static ThreadLocalThreaLocal的JDK文档中说明:ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread。如果我们希望通过某个类将状态(例如用户ID、事务ID)

2014-10-09 10:31:17 487

转载 Java ThreadLocal

suspend() and interrupt()

2014-10-09 09:30:30 478

转载 wild card matching

题目描述 (http://www.leetcode.com/onlinejudge 倒数第三题)Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (inc

2014-10-02 11:26:48 525

转载 Map-Reduce: Shuffle and Sort

IntroductionThe map phase guarantees that the input to the reducer will be sorted on its key. The process by which output of the mapper is sorted and transferred across to the reducers is known as

2014-09-30 21:17:18 682

转载 If you are given two traversal sequences, can you construct the binary tree?

It depends on what traversals are given. If one of the traversal methods is Inorder then the tree can be constructed, otherwise not.Therefore, following combination can uniquely identify a tree.

2014-09-30 21:16:02 737

转载 Check if a binary tree is subtree of another binary tree

Given two binary trees, check if the first tree is subtree of the second one. A subtree of a tree T is a tree S consisting of a node in T and all of its descendants in T.The subtree corresponding

2014-09-30 21:15:29 653

转载 The Boyer-Moore Majority Vote Algorithm

Majority ElementMajority Element: A majority element in an array A[] of size n is an element that appears more than n/2 times (and hence there is at most one such element).Write a function

2014-09-30 03:48:08 1890

转载 随机算法之蓄水池抽样问题

蓄水池抽样问题是从动态变化的N个元素中随机抽选出M个元素(N>=M)算法描述如下:Init : a reservoir with the size: k for i= k+1 to N M=random(1, i); if( M < k) SWAP the Mth value and

2014-09-30 01:07:04 672

转载 数据工程师必知算法:蓄水池抽样

引言:众所周知,想要面试一个统计学家和软件工程师的合体——数据工程师——是件很难的事情。我在面试中常使用的方法是:提出即需要算法设计,又需要一些概率论知识的问题,来考察面试者的功底。下面就是在硅谷非常流行的例子:“给出一个数据流,这个数据流的长度很大或者未知。并且对该数据流中数据只能访问一次。请写出一个随机选择算法,使得数据流中所有数据被选中的概率相等。”当面对这样一个问题的时候,

2014-09-30 01:04:18 874

转载 随机算法

1. 要求从N个元素中随机的抽取1个元素。2. 要求从N个元素中随机的抽取K个元素。int remain = Nint select = Kfor (int i = 0; i  N; ++i){   if (rand()% remain  select){      couti" ";      --select;   }   --rem

2014-09-30 01:02:59 515

原创 面试中的涉及随机的算法

- Cracking the coding interview, 17.11implement rand7() , given rand5()

2014-09-30 01:02:16 856

原创 LeetCode Gas Station

public class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { int gasSum = 0; int costSum = 0; int start = 0; int gasLeft = 0; for

2014-09-29 12:03:35 462

原创 3sum closet

public class Solution { public int threeSumClosest(int[] num, int target) { int result = Integer.MAX_VALUE; if (num == null || num.length < 3) { return result;

2014-09-29 11:49:41 480

原创 LeetCode 3sum

public class Solution { public List> threeSum(int[] num) { List> results = new ArrayList>(); if (num == null || num.length < 3) { return results; }

2014-09-29 11:06:05 388

转载 Java多线程系列目录(共43篇)

最近,在研究Java多线程的内容目录,将其内容逐步整理并发布。(一) 基础篇01. Java多线程系列--“基础篇”01之 基本概念02. Java多线程系列--“基础篇”02之 常用的实现多线程的两种方式03. Java多线程系列--“基础篇”03之 Thread中start()和run()的区别04. Java多线程系列--“基础篇”04之 synchr

2014-09-29 06:24:55 763

转载 Java多线程系列--“基础篇”09之 interrupt()和线程终止方式

概要本章,会对线程的interrupt()中断和终止方式进行介绍。涉及到的内容包括:1. interrupt()说明2. 终止线程的方式  2.1 终止处于“阻塞状态”的线程  2.2 终止处于“运行状态”的线程3. 终止线程的示例4. interrupted() 和 isInterrupted()的区别转载请注明出处:http://www.cnblogs.

2014-09-29 06:23:55 415

转载 详细分析Java中断机制

1. 引言当我们点击某个杀毒软件的取消按钮来停止查杀病毒时,当我们在控制台敲入quit命令以结束某个后台服务时……都需要通过一个线程去取消另一个线程正在执行的任务。Java没有提供一种安全直接的方法来停止某个线程,但是Java提供了中断机制。如果对Java中断没有一个全面的了解,可能会误以为被中断的线程将立马退出运行,但事实并非如此。中断机制是如何工作的?捕获或检测到中断后,是抛出

2014-09-29 05:56:46 1235

原创 复习 Core Java Chap14 多线程 笔记

14.2 中断线程在z

2014-09-29 03:30:23 482

原创 复习 Core Java Chap13 Collections 笔记

13.1.1 J

2014-09-28 06:57:42 675

GRE TESTGRE TEST

GRE TEST GUIDE GRE TEST GUIDE GRE TEST GUIDE GRE TEST GUIDE GRE TEST GUIDE

2013-08-11

dfa_trivium dfa_triviumdfa_trivium

dfa_trivium dfa_triviumdfa_trivium

2013-05-11

DE2 中文使用手册

DE2 中文使用手册

2013-05-11

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除