随笔分类 - Summary
Leetcode: Implement Trie (Prefix Tree) && Summary: Trie
摘要:参考百度百科:Trie树 a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes) The time complexity to ins
阅读全文
Lintcode: Singleton && Summary: Synchronization and OOD
摘要:Singleton is a most widely used design pattern. If a class has and only has one instance at every moment, we call this design as singleton. For exampl...
阅读全文
转载:如何在面试中写出好的代码
摘要:一下都是我面试的经验和教训,欢迎各位大牛指正或者补充 1. 写代码之前,大脑里面要有个whole picture,不能想到哪儿写到哪儿。是你的大脑在写代码,而不是白板上你的手在代码。你的手只是一个printer里面的喷头而已,是它把你大脑里面的代码print到白板上,你的大脑才是控制那个喷头的芯片。
阅读全文
VMware Coding Challenge: Possible Scores && Summary: static
摘要:Combination Sum I 那道题的变体 1 /* 2 * Complete the function below. 3 */ 4 5 static int is_score_possible(int score, int[] increments) { 6 A...
阅读全文
Summary: rand5构造rand7
摘要:给一个方法,比如 rand5(), 它能够等概率生成 1-5 之间的整数。 所谓等概率就是1,2,3,4,5 生产的概率均为 0.2 。现在利用rand5(), 构造一个能够等概率生成 1- 7 的方法。这里有两个特别重要的点,一是 如果 rand5() + rand5(), 我们能够产生一个均匀分...
阅读全文
Summary: 书架问题
摘要:Consider the problem of storing n books on shelves in a library. The order of the books is fixedby the cataloging system and so cannot be rearraged. T...
阅读全文
Summary: sorting Algorithms
摘要:Insertion sortis a simplesorting algorithmthat builds the finalsorted array(or list) one item at a time. It is much less efficient on large lists than...
阅读全文
Lintcode: Heapify && Summary: Heap
摘要:Heap的介绍1,介绍2,要注意complete tree和full tree的区别, Heap是complete tree;Heap里面 i 的 children分别是 i*2+1 和 i*2+2,i 的 parent是 (i-1)/2 Heapify的基本思路就是:Given an array
阅读全文
Lintcode: Hash Function && Summary: Modular Multiplication, Addition, Power && Summary: 长整形long
摘要:In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zer...
阅读全文
Summary: Lowest Common Ancestor in a Binary Tree & Shortest Path In a Binary Tree
摘要:转自:Pavel's BlogNow let's say we want to find the LCA for nodes 4 and 9, we will need to traverse the whole tree to compare each node so that we can lo...
阅读全文
Summary: Prime
摘要:最近遇到很多问题都跟Prime有关,于是总结一下:Prime definition:Aprime number(or aprime) is anatural numbergreater than 1 that has no positivedivisorsother than 1 and itsel...
阅读全文
Summary: Java Inheritance
摘要:In this tutorial we will discuss about the inheritance in Java. The most fundamental element of Java is the class. A class represents an entity and al...
阅读全文
Summary: difference between public, default, protected, and private key words
摘要:According to Java Tutorial:Controlling Access to Members of a ClassAccess level modifiers determine whether other classes can use a particular field o...
阅读全文
Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
摘要:转自http://www.anylogic.com/anylogic/help/index.jsp?topic=/com.xj.anylogic.help/html/code/Arrays_Collections.htmlJava offers two types of constructs whe...
阅读全文
Summary: Stack Overflow Error
摘要:What is a stack overflow error?Parameters and local variables are allocated on the stack (with reference types the object lives on the heap and a vari...
阅读全文
Twitter OA prepare: Rational Sum
摘要:In mathematics, a rational number is any number that can be expressed in the form of a fraction p/q , where p & q are two integers, and the denominato...
阅读全文
Java: Best Way to read a file
摘要:经常在各种平台的online test里面不熟悉STDIN, STOUT,下面举个例子: Input Format There are three lines of input: The first line contains an integer. The second line contains
阅读全文
Summary: gcd最大公约数、lcm最小公倍数算法
摘要:欧几里德算法欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。其计算原理依赖于下面的定理:定理:gcd(a,b) = gcd(b,a mod b)证明:a可以表示成a = kb + r,则r = a mod b假设d是a,b的一个公约数,则有d|a, d|b,而r = a - kb,因...
阅读全文
Summary: Class Variable vs. Instance Variable && Class Method
摘要:这里列举的是一些我平时碰到的一些Java Grammar,日积月累。Class Variable vs Instance Variable:Instance variablesInstance variable is the variable declared inside a class, but...
阅读全文
Leetcode: LRU Cache
摘要:难度:90。这是一道非常综合的题目,主要应用在操作系统的资源管理中。 按照题目要求,要实现get和set功能,为了满足get功能:随机访问的需求(lookup)我们首先想到的一般是用数组,如果用链表会有O(n)的访问时间。然而他又有另一个条件就是要维护least used的队列,也就是说经常用的放在
阅读全文
浙公网安备 33010602011771号