02 2015 档案
VMware coding Challenge:Date of Weekday
摘要:这道题再次证明了这种细节的题目,画个图容易搞清楚 1 import java.util.Scanner; 2 3 4 public class Solution2 { 5 static int DateOfWeekday(int date, int weekday) { 6 ...
阅读全文
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: Implement Queue by Stacks
摘要:As the title described, you should only use two stacks to implement a queue's actions.The queue should support push(element), pop() and top() where po...
阅读全文
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...
阅读全文
Lintcode: Fizz Buzz
摘要:StringBuffer的用法,append方法的参数可以使boolean, char, char[], CharSequence, double, float, int, long, String, StringBuffer Better way: http://www.cnblogs.com/E
阅读全文
Lintcode: First Bad Version
摘要:The code base version is an integer and start from 1 to n. One day, someone commit a bad version in the code case, so it caused itself and the followi...
阅读全文
Lintcode: Find Peak Element
摘要:There is an integer array which has the following features: * The numbers in adjacent positions are different. * A[0] A[A.length - 1].We define...
阅读全文
Lintcode: Fast Power
摘要:Calculate the a^n % b where a, b and n are all 32bit integers.ExampleFor 2^31 % 3 = 2For 100^1000 % 1000 = 0ChallengeO(logn)这道题跟Pow这道题很像数学问题,要求O(log n...
阅读全文
Lintcode: Delete Digits
摘要:Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according to...
阅读全文
Lintcode: Digit Counts
摘要:Count the number of k's between 0 and n. k can be 0 - 9.Exampleif n=12, in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], we have FIVE 1's (1, 10, 11, 12...
阅读全文
Lintcode: Compare Strings
摘要:Compare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Case letters.Examp...
阅读全文
Lintcode: First Position of Target (Binary Search)
摘要:Binary search is a famous question in algorithm.For a given sorted array (ascending order) and a target number, find the first index of this number in...
阅读全文
Lintcode: Binary Representation
摘要:Given a (decimal - e g 3.72) number that is passed in as a string,return the binary representation that is passed in as a string.If the number can no...
阅读全文
Lintcode: Backpack II
摘要:Given n items with size A[i] and value V[i], and a backpack with size m. What's the maximum value can you put into the backpack?NoteYou cannot divide ...
阅读全文
Lintcode: Backpack
摘要:Given n items with size A[i], an integer m denotes the size of a backpack. How full you can fill this backpack? NoteYou can not divide any item into s...
阅读全文
Lintcode: A+B problem
摘要:For given numbers a and b in function aplusb, return the sum of them.NoteYou don't need to parse the input and output. Just calculate and return.Examp...
阅读全文
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...
阅读全文