- 博客(132)
- 收藏
- 关注
原创 Medium 285题 Inorder Successor in BST
Question:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Solution:分两种情况讨论,参考了https://segmentfault.com/a/1190000003792039,存下所有路径/** * Defin
2016-11-02 13:22:20
368
原创 Medium 186题 Reverse Words in a String II
Question:Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain leading or trailing spaces and the word
2016-11-02 07:08:49
333
原创 Easy 252题 Meeting Rooms
Question:Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si i), determine if a person could attend all meetings.For example,Given [[0, 30],[
2016-10-29 02:26:32
287
原创 Hard 65题 Valid Number
Question: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 statemen
2016-10-27 11:21:35
317
原创 Hard 297题 Serialize and Deserialize Binary Tree
Question:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connec
2016-10-27 02:43:40
221
原创 Medium 47题 Permutations II
Question: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],
2016-10-26 10:52:51
199
原创 Medium 46题 Permutations
Question: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
2016-10-26 10:46:34
240
原创 Medium 311题 Sparse Matrix Multiplication
Question: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 = [
2016-10-26 08:34:39
247
原创 Easy 13题 Roman to Integer
Question:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Solution:public class Solution { public int romanToInt(String s) {
2016-10-26 08:20:54
187
原创 Easy 237题 Delete Node in a Linked List
Question:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third
2016-10-26 03:12:06
207
原创 Easy 9题 Palindrome Number
Question:Determine whether an integer is a palindrome. Do this without extra space.Solution:调试半天。。。但居然过了61%public class Solution { public boolean isPalindrome(int x) { if(x<0)
2016-10-25 12:37:45
187
原创 Easy 8题 String to Integer (atoi)
Question:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the po
2016-10-25 07:18:45
206
原创 Medium 277题 Find the Celebrity
Question: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 - 1 people kn
2016-10-25 06:10:54
206
原创 Easy 101题 Symmetric Tree
Question:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \
2016-10-25 04:10:37
200
原创 Medium 366题 Find Leaves of Binary Tree
Question:Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty.Example:Given binary tree 1
2016-10-25 01:03:26
200
原创 Medium 254题 Factor Combinations
Question: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 facto
2016-10-24 15:31:38
287
原创 Medium 256题 Paint House
Question: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 p
2016-10-24 12:43:09
192
原创 Medium 5题 Longest Palindromic Substring
Question:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Solut
2016-10-24 11:59:23
188
原创 Hard 68题 Text Justification
Question: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 a
2016-10-24 01:37:36
188
原创 Medium 364题 Nested List Weight Sum II
Question: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 intege
2016-10-22 02:09:53
217
原创 Medium 244题 Shortest Word Distance II Medium 245题 Shortest Word Distance III
Medium 244题 Shortest Word Distance II Question:This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be calledrepeate
2016-10-21 12:20:47
292
原创 Easy 243题 Shortest Word Distance
Question: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", "perfec
2016-10-21 08:57:00
181
原创 Easy 339题 Nested List Weight S
Question:Solution:DFS:/** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * public interface Nest
2016-10-20 11:35:00
413
原创 Easy 170题 Two Sum III - Data structure design
Question:Design and implement a TwoSum class. It should support the following operations: add and find.add - Add the number to an internal data structure.find - Find if there exist
2016-10-20 06:04:41
349
原创 Easy 205题 Isomorphic Strings
Question: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 rep
2016-10-20 05:02:09
311
原创 Medium 213题 House Robber II
Question:After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are a
2016-10-20 04:05:36
218
原创 Easy 198题 House Robber
Question: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
2016-10-19 13:39:53
171
原创 Easy 155题 Min Stack
Question:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stac
2016-10-18 22:55:45
160
原创 Easy 7题 Reverse Integer
Question:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Solution:用long处理溢出,注意long和int不能相加~我的笨办法public class Solution { public int re
2016-10-18 13:31:28
204
原创 Easy 6题 ZigZag Conversion
Question:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H
2016-10-18 12:10:10
184
原创 Medium 151题 Reverse Words in a String
Question:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Solution:String[] parts = s.trim().split("\\s+");S
2016-10-18 10:40:51
288
原创 Hard 146题 LRU Cache
Question: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)
2016-10-17 12:20:57
204
原创 Hard 76题 Minimum Window Substring
Question: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
2016-10-12 00:17:11
246
原创 Hard 10题 Regular Expression Matching
Question: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
2016-10-11 22:53:31
240
原创 Hard 301题 Remove Invalid Parentheses
Question:Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the paren
2016-10-11 09:26:03
192
原创 Medium 314题 Binary Tree Vertical Order Traversal
Question:Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order shou
2016-10-11 09:24:50
235
原创 Medium 98题 Validate Binary Search Tree
Question: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 th
2016-10-11 07:56:16
147
原创 Easy 157题 Read N Characters Given Read4
Question:The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 charact
2016-10-11 05:59:47
156
原创 Easy 257题 Binary Tree Paths
Question:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1-
2016-10-11 04:38:59
194
原创 Easy 278题 First Bad Version
Question: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 develop
2016-10-11 03:42:29
157
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人