[LintCode] Print Numbers by Recursion

2016-03-07
阅读 2 分钟
2.3k
Print numbers from 1 to the largest number with N digits by recursion.

[LeetCode] 108. Convert Sorted Array to Binary Search Tree

2016-03-04
阅读 2 分钟
2.8k
Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height.

[LeetCode/LintCode] Plus One

2016-03-04
阅读 2 分钟
2.4k
Given a non-negative number represented as an array of digits, plus one to the number.

[LintCode] Divide Two Integers

2016-03-03
阅读 3 分钟
2.3k
Divide two integers without using multiplication, division and mod operator.

[LintCode] Reverse Integer

2016-02-29
阅读 1 分钟
2.4k
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer).

[LeetCode] House Robber I II

2016-02-29
阅读 3 分钟
2k
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent hou...

[LintCode] Linked List Cycle I & II

2016-02-29
阅读 2 分钟
2.5k
Given -21->10->4->5, tail connects to node index 1, return true

[LintCode/LeetCode] Best Time to Buy and Sell Stock I II III IV

2016-02-29
阅读 5 分钟
2.5k
Say you have an array for which the ith element is the price of a given stock on day i.

[LintCode] Subtree

2016-02-26
阅读 2 分钟
2.3k
You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1.

[LintCode] Delete Node in the Middle of Singly Linked List

2016-02-26
阅读 1 分钟
3.2k
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.

[LintCode] Fibonacci

2016-02-26
阅读 1 分钟
2.5k
The first two numbers are 0 and 1.The i th number is the sum of i-1 th number and i-2 th number.The first ten numbers in Fibonacci sequence is:

[LintCode] Count 1 in Binary [典型位运算题目]

2016-02-26
阅读 1 分钟
3.4k
Problem Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return 1 Given 5, return 2 Given 1023, return 9 Challenge If the integer is n bits with m bits. Can you do it in O(m) time? Note 这道题,Olivia给我解决了两个疑问,还剩一个。首先是要用无符号右移运算符>>&...

[LeetCode/LintCode] Merge Intervals

2016-02-26
阅读 3 分钟
2.6k
方法上没太多难点,先按所有区间的起点排序,然后用pre和cur两个指针,如果有交集进行merge操作,否则pre向后移动。由于要求O(1)的space,就对原数组直接进行操作了。时间复杂度O(nlogn)是Collections.sort()的时间。for循环是O(n)。这道题有两个点:学会使用Collections.sort(object, new Comparator<ObjectType>...

[LintCode] Partition Array by Odd and Even

2016-02-24
阅读 1 分钟
1.8k
Partition an integers array into odd number first and even number second.

[LintCode/LeetCode] Longest Palindrome Substring

2016-02-24
阅读 3 分钟
2.5k
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

[LintCode] Valid Number

2016-02-24
阅读 2 分钟
2.1k
两种情况:有无e,如上所示。然后按有无e来拆分字符串,若拆分之后只有一部分,即用helper()函数判断是否满足构成数的规则;若有两部分,则对前一部分按数A(可以有小数部分)分析,后一部分按构成数B分析(只能为整数)。如何判断是否只有一个e?split()之后的String[]长度小于等于2。由于数A和数B的区别只存在于有没有...

[LintCode] Minimum Size Subarray Sum

2016-02-23
阅读 3 分钟
2.3k
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return -1 instead.

[LeetCode/LintCode] Valid Palindrome

2016-02-22
阅读 2 分钟
2.3k
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

[LintCode] Count of Smaller Number [二分法的活用]

2016-02-22
阅读 4 分钟
3.3k
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you an integer, return the number of element in the array that are smaller than the given integer.

[LintCode] Pow(x, n) [Binary Search]

2016-02-20
阅读 2 分钟
2k
You don't need to care about the precision of your answer, it's acceptable if the expected answer and your answer 's difference is smaller than 1e-3.

[LeetCode/LintCode] Number of Islands [DFS]

2016-02-20
阅读 3 分钟
2.5k
0 is represented as the sea, 1 is represented as the island. If two 1 is adjacent, we consider them in the same island. We only consider up/down/left/right adjacent.

[LintCode] Longest Words

2016-02-19
阅读 1 分钟
2.2k
Problem Given a dictionary, find all of the longest words in the dictionary. Example Given {代码...} the longest words are(is) ["internationalization"]. Given {代码...} the longest words are ["like", "love", "hate"]. Challenge It's easy to solve it in two passes, can you do it in one pass? Soluti...

[LintCode] Space Replacement

2016-02-19
阅读 2 分钟
2.3k
Write a method to replace all spaces in a string with %20. The string is given in a characters array, you can assume it has enough space for replacement and you are given the true length of the string.

[LintCode] Invert Binary Tree

2016-02-19
阅读 1 分钟
1.7k
Example {代码...} Solution Recursion: {代码...} Queue/linkedlist: 用queue的方法要熟练掌握。 {代码...}

[LintCode] Implement Trie

2016-02-19
阅读 4 分钟
2.1k
Insert. To insert a word(String) into a trie, by running every digit of the word in a for-loop, we have to first copy the TrieNode root into a new TrieNode cur like the way we treat TreeNode. Then we have to check if cur.children is null. If so, we create a new children with space of 26 for 26 ch...

[LintCode] Integer to Roman & Roman to Integer

2016-02-19
阅读 2 分钟
2.3k
Integer to RomanGiven an integer, convert it to a roman numeral.The number is guaranteed to be within the range from 1 to 3999.

[LintCode] Container With Most Water

2016-02-18
阅读 1 分钟
2k
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most wa...

[LintCode] Gray Code

2016-02-18
阅读 2 分钟
2.8k
The gray code is a binary numeral system where two successive values differ in only one bit.

[LintCode] Coins in a Line I & Coins in a Line II

2016-02-18
阅读 3 分钟
5.8k
There are n coins with different value in a line. Two players take turns to take one or two coins from left side until there are no more coins left. The player who take the coins with the most value wins.

[LintCode] Next Permutation II [Next Permutation]

2016-02-18
阅读 2 分钟
3.4k
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.