- 博客(74)
- 收藏
- 关注
原创 356. Line Reflection
Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points.Example 1:Given points = [[1,1],[-1,1]], return true.Example 2:Given poi
2017-03-29 13:30:02 260
原创 351. Android Unlock Patterns
Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock patterns of the Android lock screen, which consist of minimum of m keys and maxim
2017-03-28 11:21:49 527
原创 336. 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
2017-03-27 13:10:04 220
原创 333. Largest BST Subtree
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it.Note:A subtree must include all of its descendan
2017-03-25 22:33:41 273
原创 316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a
2017-03-25 09:18:49 200
原创 331. Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.
2017-03-23 11:35:58 187
原创 324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] nums[2] .Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1, 3, 2, 2, 3
2017-03-22 13:30:25 211
原创 321. Create Maximum Number
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k from digits of the two. The relative order of the digits from the same array mus
2017-03-22 11:58:46 368
原创 318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le
2017-03-21 19:26:17 195
原创 310. Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called mini
2017-03-20 15:01:34 172
原创 309. Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2017-03-20 14:14:34 191
原创 282. Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or *between the digits so they evaluate to the target value.
2017-03-13 18:14:12 195
原创 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =
2017-03-12 20:37:22 193
原创 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-03-12 20:15:26 204
原创 272. Closest Binary Search Tree Value II
Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.Note:Given target value is a floating point.You may assume k is always valid,
2017-03-12 19:35:17 198
原创 267. Palindrome Permutation II
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.For example:Given s = "aabb", return ["abba
2017-03-12 12:03:12 205
原创 261. Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n =
2017-03-12 11:40:06 327
原创 255. Verify Preorder Sequence in Binary Search Tree
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.You may assume each number in the sequence is unique.Follow up:Could you do
2017-03-11 21:07:14 198
原创 250. Count Univalue Subtrees
Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given binary tree, 5
2017-03-10 21:53:05 252
原创 241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1
2017-03-10 21:19:06 153
原创 Some useful tricks in bit manipulation
1. a + b = (a ^ b) + (a & b) Example: add a and b without the add operation.public int add(int a, int b){ while(b != 0){ int newA = a ^ b; int newB = (a & b) << 1; a =
2017-03-10 06:25:15 402
原创 233. Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the follow
2017-03-08 16:41:33 303
原创 229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Hint:How many majority elements could it po
2017-03-07 20:13:27 166
原创 223. 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
2017-03-07 07:24:06 167
原创 220. 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 absolute difference between nums[i] and nums[j] is at most t and the absolute diffe
2017-03-07 06:22:30 340
原创 214. Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam
2017-03-06 15:18:37 182
原创 212. Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor
2017-03-06 11:58:58 185
原创 201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.Solution: if m == n return mif(m != n) we can divide m and n into to partm1 | m2 n1 |
2017-03-05 14:41:51 169
原创 174. Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p
2017-03-05 14:24:33 164
原创 179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2017-03-05 13:04:05 150
原创 166. 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.
2017-03-04 17:18:01 158
原创 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2017-03-04 16:43:21 196
原创 137. Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity. Coul
2017-03-03 11:11:43 181
原创 132. Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu
2017-03-03 08:05:42 159
原创 131. Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return[ ["aa","b"],
2017-03-03 07:19:03 148
原创 188. Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may
2017-03-02 20:06:54 205
原创 128. Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3
2017-03-02 16:40:19 128
原创 129. Sum Root to Leaf Numbers (A good example to compare to Styles to solve tree problems)
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
2017-03-02 15:35:11 161
原创 124. 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
2017-03-02 15:22:21 199
原创 85. Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1
2017-03-02 12:47:25 124
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人