自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(165)
  • 收藏
  • 关注

原创 Rotate Array (Java)

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].Note:Try to come up as many solutions as yo

2015-02-27 19:35:34 437

原创 Repeated DNA Sequences (Java)

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-02-18 15:31:09 770

原创 Substring with Concatenation of All Words

You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without

2015-02-16 13:46:29 443

原创 Median of Two Sorted Arrays (Java)

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).参考:http://blog.csdn.net/yutianzui

2015-02-12 15:31:42 370

原创 Valid Number (Java)

Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo

2015-02-12 14:42:02 446

原创 Max Points on a Line (Java)

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.用斜率算,遍历每一个点,然后以这个点和剩下的所有点连线,斜率相同的放在hash的同一位置。如果有和这个点相同的点统计下来最后算进去。Source public int maxPoi

2015-02-12 14:04:17 400

原创 Palindrome Partitioning II (Java)

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

2015-02-09 11:59:54 327

原创 Candy (Java)

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on

2015-02-09 10:35:08 431

原创 Interleaving String (Java)

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret

2015-02-08 10:34:20 335

原创 Longest Valid Parentheses (Java)

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",

2015-02-08 08:55:41 328

原创 Regular Expression Matching (Java)

Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st

2015-02-07 11:21:57 395

原创 Binary Tree Maximum Path Sum (Java)

Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.

2015-02-06 21:02:30 438

原创 Insert Interval (Java)

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E

2015-02-06 19:53:47 429

原创 Merge k Sorted Lists (Java)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.merge two sorted lists那道题的升级版。Source/** * Definition for singly-linked list. * public class

2015-02-06 18:49:26 354

原创 Sudoku Solver (Java)

Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku

2015-02-06 16:24:45 300

原创 Merge Intervals (Java)

Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].Source public List merge(List interva

2015-02-06 16:04:19 357

原创 Maximal Rectangle (Java)

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.设一个数组表示从第一行开始遍历的当前列的高度,再用largest rectangle in histogram那道题的方法算最大面积。Sourcepubl

2015-02-05 10:33:20 351

原创 Scramble String (Java)

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr

2015-02-04 22:22:32 435

原创 Largest Rectangle in Histogram (Java)

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o

2015-02-04 20:56:57 343

原创 First Missing Positive (Java)

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant

2015-02-04 16:17:39 386

原创 Best Time to Buy and Sell Stock III (Java)

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may

2015-02-04 16:05:10 300

原创 Maximum Gap (Java)

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-01-31 10:32:02 1736

原创 Recover Binary Search Tree (Java)

Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis

2015-01-29 20:56:46 311

原创 Copy List with Random Pointer (Java)

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.这道题和clone graph那道题不同的地方在于,图可以d

2015-01-29 19:51:33 424

原创 Jump Game II (Java)

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i

2015-01-29 17:16:22 347

原创 Reverse Nodes in k-Group (Java)

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is

2015-01-29 16:14:10 339

原创 Permutations II (Java)

Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].

2015-01-29 12:15:18 387

原创 Distinct Subsequences (Java)

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

2015-01-29 11:52:18 348

原创 Edit Distance (Java)

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2015-01-29 11:15:44 1048

原创 Longest Consecutive Sequence (Java)

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3

2015-01-29 10:06:38 371

原创 Trapping Rain Water (Java)

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]

2015-01-24 11:50:33 300

原创 Find Minimum in Rotated Sorted Array II (Java)

Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk

2015-01-24 10:48:31 298

原创 Populating Next Right Pointers in Each Node II (Java)

Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant

2015-01-23 21:49:56 316

原创 N-Queens

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.

2015-01-23 20:36:32 305

原创 N-Queens II (Java)

Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.八皇后问题:所有皇后所在行、列、斜线上不能有其他皇后出现。用回溯法做,枚举第一行皇后可以在的所有位置,根据所在

2015-01-23 19:23:05 257

原创 Search in Rotated Sorted Array II

Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the

2015-01-23 18:08:01 271

原创 Search in Rotated Sorted Array (Java)

Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur

2015-01-23 11:35:45 309

原创 Fraction to Recurring Decimal (Java)

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.

2015-01-23 10:20:01 450

原创 Simplify Path (Java)

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did

2015-01-23 09:15:32 349

原创 Binary Search Tree Iterator (Java)

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()

2015-01-22 16:38:20 409

空空如也

空空如也

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

TA关注的人

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