Leetcode 重启
文章平均质量分 61
每天都要有进步
这个作者很懒,什么都没留下…
展开
-
Leetcode Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median原创 2016-06-24 01:18:55 · 227 阅读 · 0 评论 -
Leetcode Wiggle Sort and Wiggle Sort II
Wiggle Sort: Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] .For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].Di原创 2016-06-24 05:24:35 · 225 阅读 · 0 评论 -
Leetcode 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, in原创 2016-06-24 05:26:52 · 171 阅读 · 0 评论 -
Leetcode Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin原创 2016-06-07 21:39:04 · 210 阅读 · 0 评论 -
Leetcode Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.Difficulty: HardSolution: Traverse every pair of points, if their slope are the same, the原创 2016-06-07 21:45:45 · 228 阅读 · 0 评论 -
Leetcode Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot原创 2016-06-07 22:50:27 · 174 阅读 · 0 评论 -
Leetcode Search in Rotated Sorted Array
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原创 2016-06-07 22:56:28 · 162 阅读 · 0 评论 -
Leetcode Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found原创 2016-06-08 01:17:43 · 205 阅读 · 0 评论 -
Leetcode Nested List Weight Sum
Given a nested list of integers, return the sum of all integers in the list weighted by their depth.Each element is either an integer, or a list -- whose elements may also be integers or other lis原创 2016-06-08 02:02:51 · 238 阅读 · 0 评论 -
Leetcode Shortest Word Distance
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.For example,Assume that words = ["practice", "makes", "perfect", "coding", "原创 2016-06-08 09:08:58 · 234 阅读 · 0 评论 -
Leetcode Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums =原创 2016-06-08 09:10:54 · 218 阅读 · 0 评论 -
Leetcode Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",原创 2016-06-09 21:19:59 · 170 阅读 · 0 评论 -
Leetcode Paint House
There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the ho原创 2016-06-09 21:22:49 · 351 阅读 · 0 评论 -
Leetcode Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O原创 2016-06-10 04:49:39 · 223 阅读 · 0 评论 -
Leetcode 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 larges原创 2016-06-10 04:54:37 · 215 阅读 · 0 评论 -
Leetcode 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原创 2016-06-10 22:43:00 · 195 阅读 · 0 评论 -
Leetcode Factor Combinations
Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinations of its factors.Note:原创 2016-06-10 22:45:03 · 249 阅读 · 0 评论 -
Leetcode Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2016-06-28 12:10:01 · 149 阅读 · 0 评论 -
Leetcode Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2016-06-28 12:13:02 · 215 阅读 · 0 评论 -
Leetcode Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Difficulty: EasySolution: Check if the second char is larger than the first one.原创 2016-06-28 12:16:03 · 205 阅读 · 0 评论 -
Leetcode Palindrome Pairs
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.Example 1:Give原创 2016-06-28 12:19:03 · 177 阅读 · 0 评论 -
Leetcode Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2016-06-28 12:21:08 · 184 阅读 · 0 评论 -
Leetcode: 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].Difficulty: HardSolution:The key in this p原创 2016-06-07 00:41:04 · 182 阅读 · 0 评论 -
Leetcode Maximum 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] ha原创 2016-06-07 01:38:41 · 178 阅读 · 0 评论 -
Leetcode Combination Sum
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.The same repeated number may be chosen from C unlimited numb原创 2016-06-28 21:24:53 · 158 阅读 · 0 评论 -
Leetcode 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 nu原创 2016-06-29 05:01:14 · 163 阅读 · 0 评论 -
Leetcode Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())原创 2016-06-29 05:15:07 · 163 阅读 · 0 评论 -
Leetcode Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2016-06-29 11:50:21 · 236 阅读 · 0 评论 -
Leetcode Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Difficulty:EasySolution: Dep原创 2016-06-15 11:41:35 · 201 阅读 · 0 评论 -
Leetcode Sparse Matrix Multiplication
Given two sparse matrices A and B, return the result of AB.You may assume that A's column number is equal to B's row number.Example:A = [ [ 1, 0, 0], [-1, 0, 3]]B = [ [ 7, 0, 0 ],原创 2016-06-15 11:50:52 · 244 阅读 · 0 评论 -
Leetcode Find the Celebrity
Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1people know him/her but h原创 2016-06-15 11:53:23 · 222 阅读 · 0 评论 -
Leetcode Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a原创 2016-06-15 11:56:32 · 209 阅读 · 0 评论 -
Leetcode 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原创 2016-06-15 11:59:53 · 155 阅读 · 0 评论 -
Leetcode 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 "BAN原创 2016-06-16 04:36:07 · 163 阅读 · 0 评论 -
Leetcode Permutations
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1原创 2016-06-16 04:38:11 · 164 阅读 · 0 评论 -
Leetcode Permutations 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], [2,1原创 2016-06-16 04:39:21 · 217 阅读 · 0 评论 -
Leetcode Insert Interval
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原创 2016-06-16 04:40:38 · 165 阅读 · 0 评论 -
Leetcode Binary Search Tree Iterator
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()原创 2016-06-17 04:23:02 · 213 阅读 · 0 评论 -
Leetcode 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原创 2016-06-18 02:12:41 · 192 阅读 · 0 评论 -
Leetcode Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].Difficulty: Mediumpublic class Solution {原创 2016-06-18 02:23:11 · 180 阅读 · 0 评论