Leetcode
文章平均质量分 75
caven_y
这个作者很懒,什么都没留下…
展开
-
Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest pr原创 2014-10-24 03:43:24 · 219 阅读 · 0 评论 -
Regular Expression Matching
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原创 2014-11-02 07:56:14 · 223 阅读 · 0 评论 -
Longest Substring without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2014-11-02 06:58:56 · 158 阅读 · 0 评论 -
Max-Sum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has原创 2014-11-02 06:42:31 · 265 阅读 · 0 评论 -
Binary Tree: Inorder Traversal
11/1the classic inorder traversal, takes O(n) time and O(1) space原创 2014-11-02 06:19:12 · 243 阅读 · 0 评论 -
First Missing Integer
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 spa原创 2014-11-02 05:23:07 · 176 阅读 · 0 评论 -
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,原创 2014-11-02 04:44:27 · 212 阅读 · 0 评论 -
Sort LinkedList
In O(nlgn) time.使用merge sort, 由于使用了递归, 复杂度 T(n) 巍峨原创 2014-11-01 23:07:58 · 319 阅读 · 0 评论 -
Max Path Sum
public class Solution { public int maxPathSum(TreeNode root) { if(root == null) return 0; return maxPathSum(root, new int[1]); } private int maxPathSum(TreeNode roo原创 2014-11-01 08:36:28 · 321 阅读 · 0 评论 -
Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.10/31Solutions:The key is to原创 2014-11-01 10:22:04 · 203 阅读 · 0 评论 -
Merge Intervals
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].这道题是我在面某原创 2014-11-01 04:49:00 · 209 阅读 · 0 评论 -
Merge K Sorted List
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.11/3 这道题也跟狗家的onsite有点像, 虾米原创 2014-11-04 04:02:06 · 266 阅读 · 0 评论 -
Permutation II
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].原创 2014-11-04 02:18:10 · 293 阅读 · 0 评论 -
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原创 2014-11-04 00:39:38 · 314 阅读 · 0 评论 -
Wildcard Matching
11/1这个难题一遍组public class Solution { public boolean isMatch(String s, String p) { int slen = s.length(), plen = p.length(); int ss = 0, pp = 0; int sc = -1, pc原创 2014-11-02 10:19:16 · 207 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total原创 2014-11-03 04:17:51 · 300 阅读 · 0 评论 -
Sort Color
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.Here, we will use the integers 0,原创 2014-11-03 03:46:03 · 225 阅读 · 0 评论 -
Roate image by 90 degree in place
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?原创 2014-11-01 05:43:27 · 410 阅读 · 0 评论 -
valid BST
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The原创 2014-11-01 05:09:04 · 319 阅读 · 0 评论 -
3 Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c)原创 2014-11-01 03:44:48 · 210 阅读 · 0 评论 -
jump game II
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 is to原创 2014-10-31 23:27:44 · 216 阅读 · 0 评论 -
Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o原创 2014-11-01 02:33:25 · 172 阅读 · 0 评论 -
Combination Sum
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-11-01 22:48:54 · 221 阅读 · 0 评论 -
Subsets
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplica原创 2014-11-01 09:51:02 · 201 阅读 · 0 评论 -
经典题find median of two sorted array
10/30大概写了15分钟, 3个错, 两个typo, 一个原创 2014-10-31 05:08:50 · 472 阅读 · 0 评论 -
Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".原创 2014-10-25 02:58:13 · 190 阅读 · 0 评论 -
If a string is Palindromic
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a pa原创 2014-10-25 02:20:35 · 308 阅读 · 0 评论 -
Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each原创 2014-10-24 05:18:41 · 225 阅读 · 0 评论 -
Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to {1,4原创 2014-10-24 04:55:45 · 214 阅读 · 0 评论 -
remove duplicate from sorted list(keep only 1 per element)
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with c原创 2014-11-01 05:03:19 · 364 阅读 · 0 评论 -
reverse K listnodes
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.原创 2014-11-01 09:03:24 · 320 阅读 · 0 评论 -
Unique Path
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo原创 2014-11-02 04:28:09 · 259 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Solution 1(原创 2014-11-01 03:08:09 · 195 阅读 · 0 评论 -
Simplify path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"原创 2014-11-01 02:01:04 · 238 阅读 · 0 评论 -
Pascal Triangle
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?原创 2014-10-31 23:46:15 · 427 阅读 · 0 评论 -
Palindromic Number
in O(1) spacecompare the most significant an原创 2014-11-02 01:33:30 · 236 阅读 · 0 评论 -
Longest Valid Parenthesis
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 "()", wh原创 2014-11-02 00:59:30 · 198 阅读 · 0 评论 -
Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total原创 2014-11-02 00:34:53 · 213 阅读 · 0 评论 -
Divide Two Integers
return x/y11/1在cpublic class Solution { public int divide(int x, int y) { // return x/y /* * edge cases: * 1. x and y could be negative * 2. if原创 2014-11-01 23:50:02 · 272 阅读 · 0 评论 -
Container with Most Water
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). Fin原创 2014-11-04 00:55:28 · 228 阅读 · 0 评论