
文章平均质量分 63
lilibaobao89
这个作者很懒,什么都没留下…
展开
-
valid number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false public boolean isNumber(String s) { int i = 0, n = s.length(); boolean isNumeric = false;原创 2017-06-28 14:08:42 · 167 阅读 · 0 评论 -
101. Symmetric Tree
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 / \ / \3 4 4 3...原创 2017-05-17 14:23:02 · 171 阅读 · 0 评论 -
464. Can I Win
In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.What if we change the game so原创 2017-05-17 09:43:35 · 333 阅读 · 0 评论 -
311. 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 ],原创 2017-01-25 08:12:36 · 196 阅读 · 0 评论 -
238. 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(n).For原创 2017-05-17 13:23:24 · 173 阅读 · 0 评论 -
57. Insert Interval
Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp...原创 2017-05-20 13:42:24 · 202 阅读 · 0 评论 -
198. 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原创 2017-05-19 02:10:37 · 140 阅读 · 0 评论 -
244. Shortest Word Distance II
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 called repeatedly many times with different parameters. How would yo原创 2017-01-18 14:05:19 · 221 阅读 · 0 评论 -
243. 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", "原创 2017-01-18 08:44:45 · 312 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree
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 connection link to be...原创 2017-04-26 06:53:00 · 193 阅读 · 0 评论 -
605. Can Place Flowers
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Gi原创 2017-06-20 13:16:58 · 228 阅读 · 0 评论 -
170. Two Sum III - Data structure design
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 exists any pair of numbers w原创 2017-01-23 07:51:09 · 218 阅读 · 0 评论 -
127. 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原创 2017-02-09 09:21:30 · 288 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node原创 2017-01-31 14:35:30 · 155 阅读 · 0 评论 -
72. 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:原创 2017-06-24 13:50:43 · 181 阅读 · 0 评论 -
12. Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.要点就是要把900,400等特殊数字的表达方式加上,再按大小依次往下除即可 public String intToRoman(int num) { if(num &...原创 2017-06-30 08:28:03 · 180 阅读 · 0 评论 -
152. 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原创 2017-06-30 07:18:23 · 159 阅读 · 0 评论 -
76. 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".原创 2017-06-30 07:00:09 · 177 阅读 · 0 评论 -
515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]/** * Definition f原创 2017-06-20 13:28:18 · 214 阅读 · 0 评论 -
56. 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].public class Solution { public List merge(原创 2017-02-01 13:37:58 · 144 阅读 · 0 评论 -
146. LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key i原创 2017-04-21 08:05:34 · 308 阅读 · 0 评论 -
339. 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原创 2017-01-18 08:41:37 · 223 阅读 · 0 评论 -
50. Pow(x, n)
Implement pow(x, n).public class Solution { public double myPow(double x, int n) { if(n >= 0){ return pow(x, n); } return 1/pow(x, -n); }原创 2017-01-24 06:06:11 · 392 阅读 · 0 评论 -
205. 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原创 2017-01-23 12:33:31 · 150 阅读 · 0 评论 -
254. 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:原创 2017-01-23 12:08:43 · 236 阅读 · 0 评论 -
256. 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原创 2017-01-22 09:42:13 · 188 阅读 · 0 评论 -
156. 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原创 2017-01-19 14:18:43 · 272 阅读 · 0 评论 -
364. Nested List Weight Sum II
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原创 2017-01-19 13:31:50 · 191 阅读 · 0 评论 -
245. Shortest Word Distance III
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.Given a list of words and two words word1 and word2, return the shortest distance betwe原创 2017-01-19 08:45:19 · 216 阅读 · 0 评论 -
367. Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Returns: T原创 2017-02-09 05:43:29 · 172 阅读 · 0 评论 -
366. Find Leaves of Binary Tree
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 / \原创 2017-01-24 14:15:59 · 303 阅读 · 0 评论 -
53. 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原创 2017-01-24 14:53:05 · 150 阅读 · 0 评论 -
277. 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 - 1 people know him/her but原创 2017-01-25 08:26:21 · 258 阅读 · 0 评论 -
149. 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.public class Solution { public int maxPoints(Point[] points) { if (points == nul原创 2017-03-22 07:10:54 · 220 阅读 · 0 评论 -
46. 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原创 2017-02-03 08:55:56 · 141 阅读 · 0 评论 -
173. 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() a原创 2017-02-03 08:54:16 · 147 阅读 · 0 评论 -
47. 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原创 2017-02-03 08:51:10 · 146 阅读 · 0 评论 -
34. Search for a Range
Given an array of integers sorted in ascending order, 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原创 2017-02-01 02:29:29 · 145 阅读 · 0 评论 -
187. 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.Write原创 2017-01-31 15:20:27 · 136 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20原创 2017-01-28 08:13:38 · 170 阅读 · 0 评论