- 浏览: 571033 次
- 性别:
- 来自: 上海
最新评论
-
yuanhsh:
popu_12 写道Can you please explai ...
Pocket Gems专题 -
popu_12:
Can you please explain neighbor ...
Pocket Gems专题 -
月影无痕:
网站所有者也是www吗? 你这样做很不安全?详细原因见分析:正 ...
Ubuntu 11.10 安装 PHP, PHP-FPM, eAccelerator
文章列表
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
Follow up:Can you solve it without using extra space?
算法参见Wekipedia.
1. 假设圈的周长λ,相遇的时候乌龟走的路程:μ + k, 而兔子走的路程:μ + k + n*λ,(n代表兔子走了多少圈)
2. 因为兔子的速度是乌龟的两倍,所以兔子走的路程是乌龟的两倍,2(μ + k) = μ + k + n*λ,得到μ = n*λ - ...
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
这个要用到数学知识了。参见Wikipedia-Trailing Zeroes。
The number of trailing zeros in the decimal representation of n!, the factorial of a non-negative integer n, is simply the multi ...
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next() will return the next smallest number in the BST.
Note: next() and hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of the tre ...
Question:
Suppose you have an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). In addition, each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element o ...
Factorial digit sum
n! means n × (n − 1) × ... × 3 × 2 × 1
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!
From: https://projecteuler.net/problem=20
Solutio ...
Question:
https://projecteuler.net/problem=7
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number?
思路可以参考 wikipedia - Sieve of Eratosthenes
Solution:
public static long nthPrimeNumber(int n) {
long[] primes ...
我们谈一下实际的场景吧。我们在开发中,有如下场景
a) 关闭空闲连接。服务器中,有很多客户端的连接,空闲一段时间之后需要关闭之。b) 缓存。缓存中的对象,超过了空闲时间,需要从缓存中移出。c) 任务超时处理。在网 ...
Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",
Return 1 since the palindrome partitioning ["aa","b"] co
有一种String,是把一个更短的String重复n次而构成的,那个更短的String长度至少为2,输入一个String写代码返回true或者false
例子:"abcabcabc" true 因为它把abc重复3次构成"bcdbcdbcde" false 最后一个是bcde"abcdabcd" ...
Given an input array of number {1,2,3,4,5,6}, output number of array {2*3*4*5*6, 1*3*4*5*6,1*2*4*5*6,1*2*3*5*6,1*2*3*4*6,1*2*3*4*5 }. Do not use divide.
Solution:
public int[] getAllProductsExceptSelf(int[] num) {
if(num == null || num.length == 1) return null;
final int len = num.length ...
Replace wild cards with all possible combinations of zeros and ones using recurs
- 博客分类:
- Technical Interviews
Replace wild cards with all possible combinations of zeros and ones using recursion.
Input String: 0?1?
Output: 0010, 0011, 0110, 0111
Solution:
public List<String> replaceQuestionMark(String s) {
List<String> result = new LinkedList<String>();
replaceQuestionMarkRecu ...
Reference: https://web.cs.ship.edu/~tbriggs/dynamic/
The Integer Knapsack problem is a famous rubrick in Computer Science. The problem has a simple brute-force solution. However, solving large instances of this problem requires considerable work (run-time).
The problem is often given as a story ...
The set [1,2,3,…,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):
"123"
"132"
"213"
"231"
"312"
Given a sorted dictionary (array of words) of an alien language, find order of characters in the language.
Examples:
Input: words[] = {"baa", "abcd", "abca", "cab", "cad"}
Output: Order of characters is 'b', 'd', 'a', 'c'
Note that words are ...
Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called ‘serialization’ and reading back from the file to reconstruct the exact same binary tree is ‘deserialization’.
Approach 1.========Convert the given BST into a doubly linked list i ...