随笔分类 -  Leetcode

上一页 1 2 3 4 5 6 7 下一页

Leetcode:Same Tree
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文

posted @ 2015-01-02 20:07 Ryan-Xing 阅读(115) 评论(0) 推荐(0)

Leetcode:Recover Binary Search Tree
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文

posted @ 2015-01-02 20:00 Ryan-Xing 阅读(145) 评论(0) 推荐(0)

Leetcode:Recover Binary Search Tree
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文

posted @ 2015-01-02 20:00 Ryan-Xing 阅读(173) 评论(0) 推荐(0)

Leetcode:Populating Next Right Pointers in Each Node II
摘要:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil... 阅读全文

posted @ 2015-01-02 17:16 Ryan-Xing 阅读(129) 评论(0) 推荐(0)

Leetcode:Populating Next Right Pointers in Each Node
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文

posted @ 2015-01-02 16:24 Ryan-Xing 阅读(201) 评论(0) 推荐(0)

Leetcode:Path Sum
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo... 阅读全文

posted @ 2015-01-02 15:40 Ryan-Xing 阅读(126) 评论(0) 推荐(0)

Leetcode:Minimum Depth of Binary Tree
摘要:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文

posted @ 2015-01-02 15:10 Ryan-Xing 阅读(125) 评论(0) 推荐(0)

Leetcode:Flatten Binary Tree to Linked List
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t... 阅读全文

posted @ 2015-01-02 14:31 Ryan-Xing 阅读(144) 评论(0) 推荐(0)

Leetcode:Convert Sorted Array to Binary Search Tree
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分析:对于BST,左右子树的高度差小于等于1,则在由sorted array构建BST时把数组中间元素作为... 阅读全文

posted @ 2014-12-31 15:03 Ryan-Xing 阅读(116) 评论(0) 推荐(0)

Leetcode:Binary Tree Level Order Traversal II
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa... 阅读全文

posted @ 2014-12-29 12:53 Ryan-Xing 阅读(155) 评论(0) 推荐(0)

Leetcode:Binary Tree Level Order Traversal
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文

posted @ 2014-12-29 12:36 Ryan-Xing 阅读(129) 评论(0) 推荐(0)

Leetcode:Balanced Binary Tree
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth... 阅读全文

posted @ 2014-12-29 12:24 Ryan-Xing 阅读(112) 评论(0) 推荐(0)

Binary Tree Maximum Path Sum
摘要:class Solution {public: int maxPathSum(TreeNode *root) { if(root == NULL) return 0; int max_sum = INT_MIN; unordered_map node_... 阅读全文

posted @ 2014-12-19 21:17 Ryan-Xing 阅读(116) 评论(0) 推荐(0)

Leetcode: Evaluate Reverse Polish Notation
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文

posted @ 2014-12-15 21:30 Ryan-Xing 阅读(127) 评论(0) 推荐(0)

Leetcode: Largest Rectangle in Histogram
摘要:Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog... 阅读全文

posted @ 2014-12-12 20:34 Ryan-Xing 阅读(136) 评论(0) 推荐(0)

Leetcode: Valid Number
摘要:Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem stat... 阅读全文

posted @ 2014-12-12 12:54 Ryan-Xing 阅读(240) 评论(0) 推荐(0)

Leetcode: Anagrams
摘要:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.分析:此题的题意不是很明确,意思重新表述应该是一组string里面,有几个... 阅读全文

posted @ 2014-12-10 20:56 Ryan-Xing 阅读(156) 评论(0) 推荐(0)

Leetcode: Distinct Subsequences
摘要:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文

posted @ 2014-12-10 14:01 Ryan-Xing 阅读(129) 评论(0) 推荐(0)

Leetcode: Integer to Roman
摘要:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.分析:这道题参考leetcode.pdf的解法,代码简洁,处理的巧妙。值得借鉴的几点如下... 阅读全文

posted @ 2014-12-09 20:26 Ryan-Xing 阅读(92) 评论(0) 推荐(0)

Leetcode: Interleaving String
摘要:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文

posted @ 2014-12-09 19:46 Ryan-Xing 阅读(131) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 下一页