- 博客(61)
- 收藏
- 关注
原创 First Bad Version
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 developed based on the
2016-06-14 13:50:26
348
原创 Trie implementation -- method II
struct TrieNode { bool isEnd; vector children; TrieNode():isEnd(false){ children.resize(26, NULL); }};class Trie{ private : TrieNode* root; public :
2016-06-08 13:35:28
373
原创 98. Validate Binary Search Tree
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 the node's key.Th
2016-05-23 08:00:47
360
原创 Number of Islands II
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) into a land. Given a list of positions to opera
2016-05-13 15:10:37
517
原创 130. Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X
2016-05-13 13:42:22
393
原创 longest consecutive sequence
solutionclass Solution {public: int longestConsecutive(vector& nums) { unordered_set st; for( auto n : nums ) { st.insert(n);} int rst = 0; for( int n
2016-05-13 13:36:55
314
原创 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-05-07 13:17:09
281
原创 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
2016-05-07 10:35:28
262
原创 88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add
2016-05-07 07:21:34
294
原创 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2016-05-04 13:25:47
250
原创 53. Maximum Subarray My Submissions QuestionEditorial Solution
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-05-04 13:21:13
451
原创 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.要考虑overflowclass Solution {public: bool isPalindrome(int x) { if(x < 0) return false; in
2016-05-03 12:50:42
245
原创 Maximum Subarray
ProblemFind 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
2016-05-03 12:27:03
289
原创 Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.Solution一开始只想到从左到右横扫一遍,却没想到 divide and conquer class Solution {public: string longestCommonPrefix(v
2016-05-03 12:08:08
283
原创 LRU Cache
ProblemDesign 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) o
2016-04-30 04:49:57
341
原创 Range Sum Query - Mutable
ProblemGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i
2016-04-21 14:31:24
292
原创 316. Remove Duplicate Letters
ProblemGiven 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 lexicograp
2016-04-12 14:10:09
667
原创 sort colors
ProblemGiven 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
2016-04-04 06:21:33
370
原创 Verify Preorder Serialization of a Binary Tree
ProblemOne 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 suc
2016-03-29 15:22:55
398
原创 310. Minimum Height Trees
ProblemFor 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 ar
2016-03-28 07:26:07
239
原创 Shortest Distance from All Buildings
Problem You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a 2D grid of values 0
2016-03-25 14:48:33
643
原创 329. Longest Increasing Path in a Matrix
Problem :Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally
2016-03-24 13:11:30
278
原创 306. Additive Number
ProblemAdditive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent
2016-03-23 14:27:34
293
原创 Sparse Matrix Multiplication
ProblemGiven 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-03-21 09:12:02
283
原创 320. Generalized Abbreviation
ProblemWrite a function to generate the generalized abbreviations of a word.Example:Given word = "word", return the following list (order does not matter):["word", "1ord", "w1rd",
2016-03-14 13:41:28
327
原创 287. Find the Duplicate Number
ProblemGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one dup
2016-03-06 11:45:57
284
原创 198. House Robber
ProblemYou 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 a
2016-03-03 14:49:03
256
原创 159. Longest Substring with At Most Two Distinct Characters
ProblemGiven a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.Soluti
2016-03-02 14:41:41
285
原创 Leetcode 227. Basic Calculator II
Problemmplement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer div
2016-02-29 14:19:41
460
原创 Leetcode Binary Tree Vertical Order Traversal
ProblemSolution关键点是想到怎样把每个点投影的横坐标上的位置表示出来 : 就是把root当做0 , 向左减1,向右加1写出来是这样/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNod
2016-02-29 07:15:02
362
原创 152. Maximum Product Subarray
ProblemFind 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
2016-02-27 15:43:57
230
原创 Find Minimum in Rotated Sorted Array II
ProblemFollow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated
2016-02-26 13:54:20
223
原创 Leetcode Find Minimum in Rotated Sorted Array
ProblemSuppose 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).Find the minimum element.You may assume no duplica
2016-02-26 13:44:55
251
原创 161. One Edit Distance
ProblemGiven two strings S and T, determine if they are both one edit distance apart.Solution只有一个编辑距离,那就是只能在增,删,减中的一步Bug : 两个字符串相等时应该返回 falseclass Solution { bool helper(
2016-02-24 14:57:35
262
原创 Leetcode 187. Repeated DNA Sequences
ProblemAll 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 th
2016-02-23 15:19:05
246
原创 150. Evaluate Reverse Polish Notation
ProblemEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples:
2016-02-22 11:22:28
317
原创 Leetcode 169. Majority Element
ProblemGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majo
2016-02-21 14:52:56
262
原创 Leetcode Binary Tree Right Side View
ProblemGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary
2016-02-21 09:32:16
295
原创 Kth Largest Element in an Array
ProblemFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k =
2016-02-19 14:47:14
273
原创 [Leetcode]209. Minimum Size Subarray Sum
ProblemGiven an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given t
2016-02-19 14:24:27
272
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人