- 博客(315)
- 收藏
- 关注
原创 Leetcode Candy
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
2016-07-29 05:23:57
368
原创 Leetcode Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Diffiiculty: Medium/**
2016-07-29 05:22:43
276
原创 Leetcode Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1
2016-07-29 05:21:50
291
原创 Leetcode Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Difficulty: Mediumpublic class Soluti
2016-07-29 05:20:45
245
原创 Leetcode Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and
2016-07-29 05:19:24
240
原创 Leetcode Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2016-07-29 05:17:48
264
原创 Leetcode Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.Difficulty: Medium/** * De
2016-07-27 05:21:56
216
原创 Leetcode Fraction to Recurring Decimal
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.
2016-07-27 05:20:55
251
原创 Leetcode Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul
2016-07-27 05:19:21
230
原创 Leetcode Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Difficulty: Medium/** * Definition for a binary tree node. * public class TreeNode { *
2016-07-27 05:18:22
282
原创 Leetcode Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti
2016-07-27 05:17:31
226
原创 Leetcode Word Ladder II
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord toendWord, such that:Only one letter can be changed at a timeEach
2016-07-27 05:14:39
299
原创 Leetcode Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Difficulty: Easy/** * Defin
2016-07-27 05:13:19
202
原创 Leetcode Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Difficulty: EasySolution: Bit Manipulationpubli
2016-07-27 05:10:14
245
原创 Leetcode Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] andnums[j] is at most t and the difference between i and
2016-07-22 01:17:40
238
原创 Leetcode 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
2016-07-21 23:34:01
230
原创 Leetcode Subsets
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1],
2016-07-21 23:32:56
211
原创 Leetcode 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
2016-07-21 23:31:58
203
原创 Leetcode Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t
2016-07-21 23:30:24
204
原创 Leetcode Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2016-07-21 23:27:04
184
原创 Leetcode Unique Paths
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
2016-07-21 21:14:30
177
原创 Leetcode Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Difficulty: Mediumpublic class Solution { public String multiply(String num1, String num2) {
2016-07-20 03:51:32
135
原创 Leetcode Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is
2016-07-20 03:50:36
182
原创 Leetcode Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.
2016-07-20 03:49:35
130
原创 Leetcode 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2016-07-20 03:48:13
194
原创 Leetcode Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.Difficulty: HardSolution: http://www.programcreek.com/2014/05/leetcode-ma
2016-07-20 03:46:40
180
原创 Leetcode Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The
2016-07-20 03:44:28
129
原创 Leetcode Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-07-20 03:43:19
145
原创 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
2016-07-20 03:41:55
208
原创 Leetcode Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Difficulty: Easy/
2016-07-20 03:40:18
184
原创 Leetcode Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2016-07-20 03:38:34
146
原创 Leetcode Power of Two/Three/Four
Given an integer, write a function to determine if it is a power of two/three/four.Difficulty: Easypublic class Solution { public boolean isPowerOfTwo(int n) { if(n <= 0) return
2016-07-20 03:36:44
196
原创 Leetcode Rotate Image
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?Difficulty: Mediumpublic class Solution {
2016-07-20 03:34:10
134
原创 Leetcode Sort Colors
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
2016-07-20 01:20:42
129
原创 Leetcode Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to
2016-07-20 01:11:59
164
原创 Leetcode Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota
2016-07-20 01:09:05
169
原创 Leetcode 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], [
2016-07-20 01:06:51
217
原创 Leetcode First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the
2016-07-20 00:57:56
159
原创 Leetcode Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010
2016-07-19 05:11:33
160
原创 Leetcode Edit Distance
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:
2016-07-19 05:10:03
145
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人