- 博客(28)
- 收藏
- 关注
原创 LeetCode: Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,15,7},
2014-09-30 14:44:02 384
原创 LeetCode: Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary
2014-09-30 14:39:55 338
原创 LeetCode: Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20
2014-09-30 14:15:30 375
原创 LeetCode: Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree./** * Definition for binary tree * struct TreeNode { *
2014-09-30 13:01:46 371
原创 LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.
2014-09-30 12:38:44 341
原创 LeetCode: Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis
2014-09-27 15:28:53 413
原创 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. /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *
2014-09-27 13:17:44 311
原创 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 of the two subtrees of every node never diffe
2014-09-26 00:48:03 311
原创 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 leaf node. /** * Definition for binary tree
2014-09-25 14:38:57 366
原创 LeetCode: Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \
2014-09-25 14:20:15 373
原创 LeetCode: Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be non
2014-09-25 13:31:52 398
原创 LeetCode: Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List Total Accepted: 23135 Total Submissions: 82181My Submissions Given a binary tree, flatten it to a linked list in-place. For example, Given 1
2014-09-23 15:19:22 422
原创 LeetCode:Populating Next Right Pointers in Each Node I&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 still work? Note: You may only use constant
2014-09-23 04:09:31 408
原创 LeetCode: Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? class Soluti
2014-09-22 15:04:12 368
原创 LeetCode: Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] class Solution { public:
2014-09-22 14:52:44 337
原创 LeetCode: Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [
2014-09-22 14:27:55 374
原创 LeetCode: Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return 6.
2014-09-21 09:38:00 458
原创 LeetCode: Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that: Only one letter can be changed at a timeEach intermediate word must exi
2014-09-15 14:15:17 433
原创 LeetCode: Best Time to Buy and Sell Stock III
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 two transactions. Note: You ma
2014-09-15 10:57:30 320
原创 LeetCode: Best Time to Buy and Sell Stock II
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
2014-09-14 07:41:10 330
原创 LeetCode: Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),
2014-09-14 02:49:10 364
原创 LeetCode: Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a
2014-09-14 01:53:23 378
原创 LeetCode: Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a timeEach intermediate word m
2014-09-07 04:28:00 356
原创 LeetCode: 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
2014-09-04 13:53:43 339
原创 LeetCode: Sum Root to Leaf Numbers
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
2014-09-04 12:41:25 319
原创 LeetCode: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 X X O O X
2014-09-04 05:32:59 361
原创 LeetCode: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
2014-09-03 14:09:37 315
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人