LeetCode
文章平均质量分 57
yangyuwei11
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 / \原创 2013-08-23 17:58:33 · 344 阅读 · 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./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left;原创 2013-08-23 20:22:51 · 335 阅读 · 0 评论 -
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 {原创 2013-08-23 21:32:32 · 474 阅读 · 0 评论 -
LeetCode - Path Sum
Given a binary tree and a sum, determine if the tree has aroot-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and s原创 2013-08-23 17:38:57 · 355 阅读 · 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 leaf node./** * Definition for binary tree原创 2013-08-23 19:36:08 · 319 阅读 · 0 评论 -
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原创 2013-08-23 21:06:09 · 350 阅读 · 0 评论 -
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 binar原创 2013-08-23 21:18:25 · 431 阅读 · 0 评论 -
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./** * Definition for binary tree * struct TreeNode {原创 2013-08-23 21:40:54 · 438 阅读 · 0 评论 -
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 and the nodes have the same value./** * Defin原创 2013-08-23 22:02:56 · 303 阅读 · 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 tree should look like: 1原创 2013-08-23 17:21:12 · 312 阅读 · 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 of the two subtrees ofevery node never diff原创 2013-08-23 20:06:17 · 411 阅读 · 0 评论 -
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; *原创 2013-08-23 20:38:42 · 414 阅读 · 0 评论 -
LeetCode - Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for binary tree *原创 2013-08-23 21:14:53 · 304 阅读 · 0 评论 -
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}原创 2013-08-23 21:10:04 · 339 阅读 · 0 评论 -
LeetCode - Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2013-08-23 21:58:09 · 353 阅读 · 0 评论 -
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 3Return 6.原创 2013-08-24 13:30:10 · 345 阅读 · 0 评论 -
LeetCode - Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1原创 2013-08-24 14:32:42 · 341 阅读 · 0 评论 -
LeetCode - Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy原创 2013-08-24 16:34:29 · 337 阅读 · 0 评论 -
LeetCode - Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, t原创 2013-08-24 17:45:16 · 324 阅读 · 0 评论 -
LeetCode - Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1原创 2013-08-24 18:17:02 · 378 阅读 · 0 评论 -
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原创 2013-08-24 21:37:12 · 378 阅读 · 0 评论 -
LeetCode - Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2013-08-24 22:00:46 · 357 阅读 · 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 still work?Note:You may only use constan原创 2013-08-24 22:04:29 · 324 阅读 · 0 评论 -
LeetCode - Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string原创 2013-08-24 22:18:08 · 324 阅读 · 0 评论 -
LeetCode - Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points原创 2013-08-24 22:26:16 · 368 阅读 · 0 评论 -
LeetCode - Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2013-08-24 22:42:54 · 358 阅读 · 0 评论 -
LeetCode - Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1原创 2013-08-24 13:53:32 · 363 阅读 · 0 评论 -
LeetCode - Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-link原创 2013-08-24 17:32:14 · 318 阅读 · 0 评论 -
LeetCode - Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definition f原创 2013-08-24 17:54:01 · 335 阅读 · 0 评论 -
LeetCode - Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListN原创 2013-08-24 18:53:56 · 318 阅读 · 0 评论 -
LeetCode - Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next原创 2013-08-24 20:21:22 · 389 阅读 · 0 评论 -
LeetCode - Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each o原创 2013-08-24 21:13:04 · 355 阅读 · 0 评论 -
LeetCode - Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector &strs) { string s; if(strs.empty()){原创 2013-08-25 11:19:00 · 334 阅读 · 0 评论 -
LeetCode - Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?class Solution {public: i原创 2013-08-25 14:00:55 · 396 阅读 · 0 评论 -
LeetCode - Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector anagrams(vector &strs) { vector原创 2013-08-25 14:49:38 · 365 阅读 · 0 评论 -
LeetCode - Maximum Subarray
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原创 2013-08-25 17:28:17 · 371 阅读 · 0 评论 -
LeetCode - Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or righ原创 2013-08-25 20:28:01 · 392 阅读 · 0 评论 -
LeetCode - Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2013-08-26 10:41:33 · 392 阅读 · 0 评论 -
LeetCode - String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input原创 2013-08-25 10:59:08 · 313 阅读 · 0 评论 -
LeetCode - Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa"原创 2013-08-25 11:54:53 · 349 阅读 · 0 评论
分享