[LintCode] Backpack I & II

2016-04-13
阅读 2 分钟
2.2k
Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this backpack?

[LintCode] Hash Function

2016-04-13
阅读 2 分钟
3k
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 zero. The objective of designing a hash function is to "hash" the key as unreasonable as possible. A good hash function can avoid collision as less as...

[LintCode] Topological Sorting [BFS & DFS]

2016-04-11
阅读 3 分钟
3.7k
Given an directed graph, a topological order of the graph nodes is defined as follow:

[LintCode] Rehashing

2016-04-09
阅读 2 分钟
2.4k
The size of the hash table is not determinate at the very beginning. If the total size of keys is too large (e.g. size >= capacity / 10), we should double the size of the hash table and rehash every keys. Say you have a hash table looks like below:

[LintCode] Heapify

2016-04-09
阅读 2 分钟
2.5k
For a heap array A, A[0] is the root of heap, and for each A[i], A[i * 2 + 1] is the left child of A[i] and A[i * 2 + 2] is the right child of A[i].

[LintCode/LeetCode] Implement Trie

2016-04-08
阅读 3 分钟
2.6k
首先,我们应该了解字典树的性质和结构,就会很容易实现要求的三个相似的功能:插入,查找,前缀查找。既然叫做字典树,它一定具有顺序存放26个字母的性质。另外,为了实现和区别全词查找和前缀查找,应该有一个标记。所以,在字典树的class里面,添加ch,exist和children三个参数。

[LintCode/LeetCode] Clone Graph [BFS/DFS]

2016-04-08
阅读 4 分钟
2.6k
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.

[LintCode] Subarray Sum

2016-04-07
阅读 1 分钟
2.3k
Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number.

[LintCode] Submatrix Sum

2016-04-06
阅读 2 分钟
3.7k
Given an integer matrix, find a submatrix where the sum of numbers is zero. Your code should return the coordinate of the left-up and right-down number.

[LintCode] Fast Power

2016-04-06
阅读 1 分钟
2.1k
Problem Calculate the a^n % b where a, b and n are all 32bit integers. Example For 2^31 % 3 = 2 For 100^1000 % 1000 = 0 Challenge O(logN) Note 应用求余公式: (a * b) % p = (a % p * b % p) % p使用分治法,不断分解a^n为a^(n/2),最终的子问题就是求解a^1或者a^0的余数。唯一要注意的就是,若n为奇数,要将余...

[LintCode] Interleaving Positive and Negative Numbers

2016-04-05
阅读 2 分钟
2.6k
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.

[LintCode/LeetCode] Sort Colors I & II

2016-04-05
阅读 3 分钟
3.6k
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.

[LintCode/LeetCode] Combination Sum I & II

2016-04-05
阅读 3 分钟
3.1k
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.

[LintCode/LeetCode] Combinations

2016-04-05
阅读 2 分钟
2k
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

[LintCode] Unique Characters

2016-04-04
阅读 1 分钟
2.5k
Implement an algorithm to determine if a string has all unique characters.

[LintCode/LeetCode] Two Strings are Anagrams/Valid Anagram

2016-04-04
阅读 2 分钟
2k
Write a method anagram(s,t) to decide if two strings are anagrams or not.

[LintCode/LeetCode] Find Minimum in Rotated Sorted Array I & II

2016-04-04
阅读 2 分钟
1.6k
Suppose a sorted array is rotated at some pivot unknown to you beforehand.

[LintCode/LeetCode] Rotate Image

2016-04-04
阅读 3 分钟
2.7k
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).

[LintCode/LeetCode] Two Sum

2016-04-03
阅读 2 分钟
2.4k
Given an array of integers, find two numbers such that they add up to a specific target number.

[LintCode/LeetCode/CC] Set Matrix Zeroes

2016-04-03
阅读 2 分钟
2.1k
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

[LeetCode] 96. Unique Binary Search Trees I & 95. II

2016-04-03
阅读 2 分钟
3.1k
Given n, how many structurally unique BSTs (binary search trees) that store values 1...n?

[LintCode/LeetCode] Merge Two Sorted Lists

2016-04-03
阅读 1 分钟
2.1k
Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the two lists and sorted in ascending order.

[LintCode/LeetCode] Nth to Last Node in List

2016-04-03
阅读 1 分钟
1.7k
Given a List 3->2->1->5->null and n = 2, return node whose value is 1.

[LintCode/LeetCode] Add Two Numbers

2016-03-29
阅读 2 分钟
2.2k
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.

[LintCode/LeetCode] Rotate List

2016-03-29
阅读 1 分钟
1.9k
Given a list, rotate the list to the right by k places, where k is non-negative.

[LintCode] Anagrams

2016-03-29
阅读 2 分钟
1.9k
Given an array of strings, return all groups of strings that are anagrams.

[LintCode/LeetCode] Remove Element [Two Pointers]

2016-03-29
阅读 1 分钟
2.5k
Given an array and a value, remove all occurrences of that value in place and return the new length.

[LintCode] Insertion Sort List

2016-03-29
阅读 1 分钟
2.7k
Given 1->3->2->0->null, return 0->1->2->3->null.

[LeetCode/LintCode] Remove Nth Node From End of List

2016-03-29
阅读 1 分钟
1.8k
Given a linked list, remove the nth node from the end of list and return its head.

[LintCode] Route Between Two Nodes in Graph [DFS/BFS]

2016-03-29
阅读 2 分钟
2.6k
Given a directed graph, design an algorithm to find out whether there is a route between two nodes.