- 博客(97)
- 资源 (3)
- 收藏
- 关注
原创 [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",
2014-06-30 23:56:33 768
原创 [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.
2014-06-30 05:19:30 809
原创 [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
2014-06-30 01:24:35 2697 1
原创 [LeetCode]Word BreakII
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "
2014-06-27 00:03:28 878
原创 [LeetCode]Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi
2014-06-26 23:13:14 1021
原创 [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
2014-06-26 22:46:38 709
原创 [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
2014-06-26 03:49:29 2706 2
原创 [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 ea
2014-06-26 01:38:32 3024
原创 [LeetCode131]Surrounded Region
Analysis:Search is a good way to solve this problem!First and easy thought might, scan all the element, if meets 'O', looking for a path to the boundary, if not exist, put it to 'X'. To look for t
2014-06-26 00:12:45 753
原创 [LeetCode130]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 tota
2014-06-25 23:23:55 646
原创 [LeetCode127]Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m
2014-06-25 01:11:33 770
原创 [LeetCode126] Valid Palindrome
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
2014-06-24 23:58:05 756
原创 [LeetCode65]Pascal's Triangle II
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?Analysis:
2014-06-24 22:56:17 1173
原创 [LeetCode64]Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Analysis:根据帕斯卡三角的定义Java
2014-06-24 03:27:32 1709
原创 [LeetCode73]Populating Next Right Pointers in Each Node II
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
2014-06-24 01:35:33 774
原创 [LeetCode72]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.
2014-06-24 01:12:27 764
原创 [LeetCode13]Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},
2014-06-24 00:58:31 712 1
原创 [LeetCode83]Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2014-06-24 00:34:30 849
原创 [LeetCode26]Decode Ways
The key to this problem is : num(current) = num(current-1) + num(current-2).Be careful with the conditions of above equation:if the current char =='0'if the current char and previous char >26i
2014-06-23 03:51:03 820
原创 [LeetCode32]Gary Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2014-06-23 02:05:49 1257
原创 [LeetCode53]Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from
2014-06-23 01:48:49 629
原创 [LeetCode47]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.Analysis:
2014-06-23 01:29:50 860
原创 [LeetCode40]Largest Rectangle in Histogram
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
2014-06-23 00:37:09 864
原创 [LeetCode95]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
2014-06-22 05:16:05 657
原创 [LeetCode78]Remove Duplicates from Sorted Array II
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
2014-06-22 04:49:22 611
原创 [LeetCode124]Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically
2014-06-22 01:23:39 765
原创 [LeetCode105]Subsets II
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 dupli
2014-06-22 00:28:23 826
原创 [LeetCode104]Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa
2014-06-21 23:59:22 683
原创 [LeetCode19]Combinations
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-06-21 23:37:28 683
原创 [LeetCode99]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
2014-06-20 06:23:36 836
原创 [LeetCode]Simplify Path
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
2014-06-20 05:50:58 503
原创 [LeetCode102]Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.Analysis:In an interview, they expected the solution is using binary search, not Newton's Method.Javapublic int sqrt
2014-06-20 01:01:50 726
原创 [LeetCode110]Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i
2014-06-20 00:38:28 894
原创 [LeetCode71]Plus one
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.
2014-06-19 23:41:17 1444
原创 [LeetCode118]Valid Number
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
2014-06-19 23:09:27 768
原创 [LeetCode4]Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Analysis:
2014-06-19 00:56:55 798
原创 [LeetCode35]Insert Intervals
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
2014-06-19 00:18:27 803
原创 [LeetCode51]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].Analysis:
2014-06-18 23:47:42 617
原创 [LeetCode60]N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Anal
2014-06-18 05:34:36 2739
原创 [LeetCode59]N-Queens
Javapublic class Solution { List result; int[] A; public List solveNQueens(int n) { result = new ArrayList(); A = new int[n]; nqueens(0, n); return result; } public void nqueens(i
2014-06-18 05:27:00 2752
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人