![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 66
sherry612
这个作者很懒,什么都没留下…
展开
-
[Leetcode] Sum Root to Leaf Numbers
题目: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 / \原创 2014-10-13 12:10:01 · 217 阅读 · 0 评论 -
[Leetcode] Letter Combinations of a Phone Number
题目:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note原创 2014-10-17 09:43:44 · 277 阅读 · 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原创 2014-10-17 10:32:51 · 214 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted Array II
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A原创 2014-10-17 11:06:20 · 292 阅读 · 0 评论 -
[Leetcode] Search for a Range
题目: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原创 2014-10-18 05:39:10 · 236 阅读 · 0 评论 -
[Leetcode] N-Queens
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutio原创 2014-10-20 05:36:20 · 207 阅读 · 0 评论 -
[Leetcode] Search in Rotated Sorted Array
题目:Divide two integers without using multiplication, division and mod operator.思路:D = a0 * d * 2^n + a1 * d * 2^(n-1) + ... + an * d * 2^0,从d * 2^n开始,不断的用被除数减去这个值,同时计算ai.最终原创 2014-10-18 04:59:27 · 222 阅读 · 0 评论 -
[Leetcode] Combination Sum
题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the t原创 2014-10-18 09:36:30 · 235 阅读 · 0 评论 -
[Leetcode] Multiply Strings
题目:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.思路:递归寻找所有可能。原创 2014-10-20 01:56:00 · 220 阅读 · 0 评论 -
[Leetcode] Divide Two Integers
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is原创 2014-10-18 03:41:20 · 213 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do t原创 2014-10-17 10:53:54 · 245 阅读 · 0 评论 -
[Leetcode] Swap Nodes in Pairs
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:建立一个heap,将每个list的第一个node放入heap中,每次将堆顶的元素拿出来放到最终结果中。class Solution {原创 2014-10-05 10:52:08 · 219 阅读 · 0 评论 -
[Leetcode] 4Sum
题目:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.N原创 2014-10-01 10:53:02 · 214 阅读 · 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: void swap(int& a,原创 2014-10-06 13:12:13 · 214 阅读 · 0 评论 -
[Leetcode] Permutations
题目:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].原创 2014-10-06 11:29:34 · 187 阅读 · 0 评论 -
[Leetcode] Subsets
题目:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2],原创 2014-10-13 07:16:33 · 246 阅读 · 0 评论 -
[Leetcode] Median of Two Sorted Arrays
题目: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原创 2014-10-14 08:05:56 · 333 阅读 · 0 评论 -
[Leetcode] Reverse Integer
题目: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.原创 2014-10-14 08:53:17 · 221 阅读 · 0 评论 -
[Leetcode] Palindrome Partitioning II
题目: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原创 2014-11-01 04:29:12 · 242 阅读 · 0 评论 -
[Leetcode] Add Two Numbers
题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as原创 2014-10-04 08:29:29 · 177 阅读 · 0 评论 -
[Leetcode] Reverse Linked List
题目:LeLeetcode上并没有这道题,但是由于和inorder类似,所以写上来。思路:递归的做法非常简单,重点是如何用循环来做。 整体思路是利用一个堆栈去模拟递归的过程,问题是,如果完全按照递归的过程去做堆栈,那么对于栈顶的元素A需要将左子树压入堆栈,然后当左边的元素弹出堆栈后,弹出A,然后再将右子树压入堆栈。这样,元素A有两次成为原创 2014-10-16 11:20:16 · 379 阅读 · 0 评论 -
[Leetcode] Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once原创 2014-10-18 09:49:30 · 194 阅读 · 0 评论 -
[Leetcode] N-Queens II
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-原创 2014-10-20 07:07:58 · 219 阅读 · 0 评论 -
[Leetcode] Search a 2D Matrix
题目:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The fi原创 2014-10-21 02:49:00 · 209 阅读 · 0 评论 -
[Leetcode] Binary Tree Inorder Traversal
题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note:原创 2014-10-16 05:21:05 · 263 阅读 · 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 loo原创 2014-10-22 11:13:01 · 247 阅读 · 0 评论 -
[Leetcode] Construct Binary Tree from Inorder and Postorder 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:原创 2014-10-22 09:39:48 · 229 阅读 · 0 评论 -
[Leetcode] Minimum Window Substring
题目: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原创 2014-11-06 11:43:27 · 379 阅读 · 0 评论 -
[Leetcode] Permutations II
题目:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1],原创 2014-11-06 14:05:23 · 292 阅读 · 0 评论 -
[Leetcode] Sort List
题目:Sort a linked list in O(n log n) time using constant space complexity.思路:O(nlogn)的sort有quick sort, merge sort, heap sort. 首先排除heap sort, heap需要用到O(n)的空间。其次排除quick sort,原创 2014-11-30 10:14:54 · 272 阅读 · 0 评论 -
[Leetcode] Implement strStr()
题目:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.思路:二分法。class Solution {public: double原创 2014-10-02 04:46:15 · 232 阅读 · 0 评论 -
[Leetcode] Binary Tree Postorder Traversal
题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note:原创 2014-10-16 06:13:16 · 284 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted List II
题目: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.思路:两个指原创 2014-10-21 03:49:03 · 497 阅读 · 0 评论 -
[Leetcode] Unique Paths II
题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to r原创 2014-10-21 00:24:38 · 213 阅读 · 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原创 2014-10-21 00:39:57 · 238 阅读 · 0 评论 -
[Leetcode] Search in Rotated Sorted Array II
题目:Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given tar原创 2014-10-21 03:07:54 · 239 阅读 · 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.原创 2014-10-21 03:21:55 · 240 阅读 · 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 to x.You should preserve the original relative order of the nod原创 2014-10-21 04:05:37 · 220 阅读 · 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 ex原创 2014-10-21 05:06:35 · 260 阅读 · 0 评论 -
[Leetcode] Edit Distance
题目:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations per原创 2014-10-21 02:31:20 · 232 阅读 · 0 评论