自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(173)
  • 资源 (1)
  • 收藏
  • 关注

原创 Minimum size subarray sum

iven 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 0 instead.For example, given the array [2,3,

2015-05-18 06:15:08 927

原创 Course schedule II

和course schedule一样的要求,只是要求输出toplogicl排序的结果。一个tricky的地方就是如果没有正常结果,输出new int[0public class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { int[] result = new int

2015-05-18 06:13:47 512

原创 Lintcode - Convert Expression to Polish Notation

Given an expression string array, return the Polish notation of this expression. (remove the parentheses)ExampleFor the expression [(5 − 6) * 7] (which represented by ["(", "5", "−", "6", ")

2015-05-15 13:12:13 2070

原创 Lintcode - Convert Expression to Reverse Polish Notation

Given an expression string array, return the Polish notation of this expression. (remove the parentheses)ExampleFor the expression [(5 − 6) * 7] (which represented by ["(", "5", "−", "6", ")

2015-05-15 13:10:32 2085

原创 Lintcode - Expression Evaluation

Given an expression string array, return the final result of this expressionExampleFor the expression 2*6-(23+7)/(1+2), input is[ "2", "*", "6", "-", "(", "23", "+", "7", ")", "/", (

2015-05-15 09:46:44 3093 1

原创 Producer Consumer problem - mutex and semaphore

很典型的一道多线程题目。如果使用BlockingQueue,就十分简单。下面是自己实现的两个线程,使用mutex 方法 wait() and notify()package concurrent;import java.util.LinkedList;import java.util.Queue;import java.util.concurrent.Semaphore;pub

2015-05-12 12:16:16 871

原创 Course Schedule

There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as

2015-05-11 13:12:18 605

原创 Lintcode - Segment Tree Modify

For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in this node's interval.Implement a modify function with three parameter root, index and value to

2015-05-03 07:39:22 1087

原创 Lintcode - Segment Tree Query

For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding SegmentTree, each node stores an extra attributemax to denote the maximum number in the interval o

2015-05-03 07:17:19 1646

原创 Lintcode - Segment Tree Build

The structure of Segment Tree is a binary tree which each node has two attributes start andend denote an segment / interval.start and end are both integers, they should be assigned in following

2015-05-03 07:13:22 1490

原创 Dungeon Gam

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p

2015-04-28 06:21:23 395

原创 Repeated DNA Sequences

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri

2015-04-28 05:24:07 406

原创 Binary Tree Right Side View

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1

2015-04-26 08:22:27 413

原创 Bitwise AND of Numbers Range

Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.核心就是求m 和n的最高位是否在一个位置上。我们把n的所有低位置零,只剩下最高位,然后&m。结果或者是两个的最高位,或者是0. public int rangeBitwiseAnd(int m, i

2015-04-26 07:07:42 363

原创 Reservoir sampling

Having an input stream of n, select k elements with equal probability.Algorithm: 1. select k elements into the result first 0....k-12. for k....n-1 elements, each time i, generate a random n

2015-04-17 11:58:43 657

原创 Pretty print binary tree

http://articles.leetcode.com/2010/09/how-to-pretty-print-binary-tree.html简化版本的C++const int box_size = 3;std::queue q;q.push(m_root);size_t current_level_nodes = 1;size_t next_current_level_n

2015-04-12 03:28:24 692

原创 Save BST to a file

http://articles.leetcode.com/2010/09/saving-binary-search-tree-to-file.htmlpreorder traversal将bst存下来。如何恢复?依然preorder。母节点的数值决定了子节点可以存储的范围,所以我们拿到一个新的数字时,看他是不是在母节点的规定范围内;否则就继续到母节点的另外一个子树中尝试。p

2015-04-12 02:26:38 392

原创 Number of 1 Bits

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000

2015-04-11 13:55:25 364

原创 Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, i

2015-04-08 13:28:53 454

原创 Sqrt double

EPI: https://code.google.com/p/elements-of-programming-interviews/source/browse/trunk/Square_root.cpp public static double sqrt(double num) { double left = 0, right = 0; if (num <

2015-04-07 12:31:33 951

原创 House Robber

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 house

2015-04-01 12:52:04 649

转载 Coin change

http://www.fgdsb.com/2015/01/03/coin-change-problem/#moreGiven a set of currency denominations, find the minimum number of coins needed to represent an amount.1234567891011121314

2015-04-01 11:22:41 424

原创 Wildcard Matching

'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype shoul

2015-03-30 08:50:52 392

原创 Rotate Array

Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4] public void rotate(int[] nums, int k) {

2015-03-30 05:20:19 321

原创 Largest Number

Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve

2015-03-29 12:49:03 377

原创 LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if

2015-03-29 06:24:35 395

原创 Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements

2015-03-26 13:21:51 394

原创 Longest Substring with At Most Two Distinct Characters

Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.和minimum window一样的题。一遍过

2015-03-26 11:55:27 503

原创 Lintcode - Maximum Subarray III

Given an array of integers and a number k, find knon-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum.NoteThe su

2015-03-24 05:21:00 4383 1

原创 Remove element

Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.简单题

2015-03-24 02:29:48 405

原创 Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin

2015-03-23 05:09:41 332

原创 Lintcode - Maximum Subarray Difference

Given an array with integers.Find two non-overlapping subarrays A and B, which|SUM(A) - SUM(B)| is the largest.Return the largest difference.NoteThe subarray should contain at least on

2015-03-20 13:02:48 4648

原创 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 item into small pieces and the total siz

2015-03-17 13:13:10 2345

原创 Lintcode - Minimum Adjustment Cost

Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.If the array before adjustment is A, the array after adjust

2015-02-17 15:39:03 3426

原创 Lintcode - Previous Permutation

Given a list of integers, which denote a permutation.Find the previous permutation in ascending order.NoteThe list may contains duplicate integers.ExampleFor [1,3,2,3], the pre

2015-02-13 15:21:52 4860

原创 Lintcode - k sum II

Given n unique integers, number k (1ExampleGiven [1,2,3,4], k=2, target=5, [1,4] and [2,3] are possible solutions. public ArrayList> kSumII(int A[], int k, int target) { Array

2015-02-09 14:42:57 1848

原创 Lintcode - Remove Node in Binary Search Tree

Given a root of Binary Search Tree with unique value for each node.  Remove the node with given value. If there is no such a node with given value in the binary search tree, do nothing. You should kee

2015-02-09 11:33:08 1819

原创 Lintcode - Serialization and Deserialization Of Binary Tree

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

2015-02-09 09:09:26 1343

原创 Lintcode - Maximum Subarray II

Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum.NoteThe subarray shoul

2015-02-08 15:12:28 4144

原创 Lintcode - Majority Number III

Given an array of integers and a number k, the majority number is the number that occurs more than 1/k of the size of the array. Find it.NoteThere is only one majority number in the array.

2015-02-08 14:32:07 4070 1

Introduction to Algorithms

mit 2rd edition introduction to algorithms

2009-08-26

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除