自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(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 324

原创 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 343

原创 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 336

原创 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 487

原创 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 370

原创 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 282

原创 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 254

原创 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 239

原创 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 274

原创 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 225

原创 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 423

原创 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 220

原创 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 251

原创 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 260

原创 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 314

原创 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 272

原创 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 634

原创 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 348

原创 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 374

原创 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 211

原创 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 619

原创 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 260

原创 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 274

原创 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 264

原创 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 298

原创 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 272

原创 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 242

原创 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 269

原创 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 438

原创 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 340

原创 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 217

原创 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 212

原创 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 240

原创 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 250

原创 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 237

原创 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 307

原创 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 255

原创 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 277

原创 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 250

原创 [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 260

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除