
LeetCode
SharonMoMo
Every thing will be okay in the end....
展开
-
[LeetCode244]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 you o原创 2015-11-24 07:06:24 · 442 阅读 · 0 评论 -
[LeetCode156] Binary Tree Upside Down
今天开始先把leetcode收费题思路整理到这里,因为只买了一个月。。。==, 用中文吗。Binary Tree Upside Down My Submissions QuestionTotal Accepted: 6016 Total Submissions: 16909 Difficulty: MediumGiven a binary tree where all the right nod原创 2015-11-24 03:43:54 · 456 阅读 · 0 评论 -
[LeetCode311]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原创 2015-11-29 07:33:29 · 2276 阅读 · 0 评论 -
[LeetCode302]Smallest Rectangle Enclosing Black Pixels
Hard ..An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black pixels are connected, i.e., there is only one black region. Pixels are connected horizontally原创 2015-11-29 07:18:09 · 798 阅读 · 0 评论 -
[LeetCode298]Binary Tree Longest Consecutive Sequence
Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections原创 2015-11-29 07:12:38 · 627 阅读 · 0 评论 -
[LeetCode293] Flip Game
EasyYou are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". The原创 2015-11-29 06:57:29 · 1005 阅读 · 0 评论 -
[LeetCode305]Number of Islands II
Hard..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 op原创 2015-11-29 07:24:44 · 883 阅读 · 0 评论 -
[LeetCode288]Unique Word Abbreviation
An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations:a) it --> it (no abbreviation) 1b) d|o|g原创 2015-11-26 13:17:43 · 606 阅读 · 0 评论 -
[LeetCode285]Inorder Successor in BST
Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in-order successor in the tree, return null.Hide Tags TreeHide Similar P原创 2015-11-26 08:22:47 · 992 阅读 · 0 评论 -
[LeetCode277]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 he/sh原创 2015-11-26 05:41:48 · 388 阅读 · 0 评论 -
[LeetCode282]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, that is:原创 2015-11-26 06:26:34 · 368 阅读 · 0 评论 -
[LeetCode281]Zigzag Iterator
Given two 1d vectors, implement an iterator to return their elements alternately.For example, given two 1d vectors:v1 = [1, 2]v2 = [3, 4, 5, 6]By calling next repeatedly until hasNext returns false,原创 2015-11-26 05:58:57 · 415 阅读 · 0 评论 -
[LeetCode280] Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3]....For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].Hide Comp原创 2015-11-26 05:49:22 · 391 阅读 · 0 评论 -
[LeetCode308]Range Sum Query 2D - Mutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).Range Sum Query 2DThe above rectangle (wit原创 2015-11-29 07:27:19 · 4520 阅读 · 0 评论 -
[LeetCode291]Word Pattern II
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty substring in str.Exampl原创 2015-11-29 06:54:06 · 524 阅读 · 0 评论 -
[LeetCode325] Maximum Size Subarray Sum Equals k
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given nums = [1, -1, 5, -2, 3], k = 3,return 4. (because原创 2016-01-08 15:34:02 · 2013 阅读 · 0 评论 -
[LeetCode314]Binary Tree Vertical Order Traversal
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 should be from left to r原创 2015-12-07 07:08:17 · 1739 阅读 · 1 评论 -
[LeetCode222]Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and a原创 2015-12-04 14:48:55 · 360 阅读 · 0 评论 -
[LeetCode212] Word Search II
HARDGiven 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 hori原创 2015-12-04 04:49:52 · 465 阅读 · 0 评论 -
[LeetCode202]Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of i原创 2015-12-03 05:43:41 · 420 阅读 · 0 评论 -
[LeetCode187]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 a原创 2015-12-02 08:43:02 · 303 阅读 · 0 评论 -
[LeetCode186]Reverse Words in a String II
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 words are always sep原创 2015-11-24 06:37:11 · 439 阅读 · 0 评论 -
[LeetCode315] Count of Smaller Numbers After Self
我靠!弄了一个小时!class node{public: int height, size, val; node *left, *right; node(int val){ this->val = val; this->height = 1; this->size = 1; this->left = this-原创 2015-12-07 09:41:37 · 800 阅读 · 0 评论 -
[LeetCode317]Shortest Distance from All Buildings
You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You are given a 2D grid of values 0, 1 or 2, where:Each 0 marks an empty land which you can pa原创 2015-12-17 03:59:18 · 2502 阅读 · 0 评论 -
[LeetCode164]Maximum Gap
HARDGiven an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.You原创 2015-11-30 13:06:24 · 411 阅读 · 0 评论 -
[LeetCode296]Best Meeting Point
A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance is calcul原创 2015-11-29 07:07:54 · 468 阅读 · 0 评论 -
[LeetCode294]Flip Game II
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". The gam原创 2015-11-29 07:05:11 · 588 阅读 · 0 评论 -
[LeetCode276]Paint Fence
There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more than two adjacent fence posts have the same color.Return the total num原创 2015-11-26 05:33:49 · 1021 阅读 · 0 评论 -
[LeetCode270]Closest Binary Search Tree Value
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note: Given target value is a floating point. You are guaranteed to have only on原创 2015-11-26 04:28:46 · 481 阅读 · 0 评论 -
[LeetCode265]Paint House II
There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adj原创 2015-11-26 02:58:41 · 592 阅读 · 0 评论 -
[LeetCode170]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 which s原创 2015-11-24 06:19:53 · 326 阅读 · 0 评论 -
[LeetCode157]Read N Characters Given Read4
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 characters left in the file原创 2015-11-24 04:19:07 · 349 阅读 · 0 评论 -
[LeetCode243]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", "makes"原创 2015-11-24 06:40:33 · 355 阅读 · 0 评论 -
[LeetCode246] Strobogrammatic Number
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to determine if a number is strobogrammatic. The number is represented as a st原创 2015-11-24 09:01:14 · 355 阅读 · 0 评论 -
[LeetCode247]Strobogrammatic Number II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Find all strobogrammatic numbers that are of length = n.For example,Given n = 2, return ["11",原创 2015-11-24 09:19:56 · 560 阅读 · 0 评论 -
[LeetCode161] One Edit Distance
Given two strings S and T, determine if they are both one edit distance apart.Hide Company Tags Uber FacebookHide Tags StringHide Similar Problems (H) Edit Distance所谓Edit distance, 一次delete, insert原创 2015-11-24 05:36:11 · 293 阅读 · 0 评论 -
[LeetCode261] 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 = 5 and edges原创 2015-11-25 12:45:28 · 999 阅读 · 0 评论 -
[LeetCode160]Longest Substring with At Most Two Distinct Characters
Given 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.Hide Company Tags GoogleHide Tags原创 2015-11-24 05:19:48 · 245 阅读 · 0 评论 -
[LeetCode248]Strobogrammatic Number III
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to count the total strobogrammatic numbers that exist in the range of low <= n原创 2015-11-24 09:48:58 · 759 阅读 · 0 评论 -
[LeetCode245] 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 between thes原创 2015-11-24 07:14:21 · 312 阅读 · 0 评论