算法分析与设计
文章平均质量分 62
SYSU_Chan
这个作者很懒,什么都没留下…
展开
-
算法分析与设计——LeetCode Problem.4 Median of Two Sorted Arrays
题目链接问题详情:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 =原创 2017-09-24 22:35:19 · 178 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.538 Convert BST to Greater Tree
题目链接问题描述Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the orig原创 2017-12-29 12:23:02 · 232 阅读 · 0 评论 -
《算法概论》习题8.9
题目如下:证明: 可将顶点覆盖问题归约到碰撞集问题,顶点覆盖问题的目标是找到一个大小不超过b的点集合H,使得图中所有的边都至少与集合中的一个点关联,它是一个NP-完全问题。 设无向图G=(V,E),对于图中每一条边(Vm,Vn),设集合Si={Vm,Vn},最终得到|E|个集合。 这样即可将顶点覆盖问题归约到碰撞集问题: ① 若存在满足要求的集合H,它与原创 2018-01-06 00:11:01 · 367 阅读 · 0 评论 -
Leetcode 154. Find Minimum in Rotated Sorted Array II
题目链接问题描述Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose an array sorted in ascending order is rotated...原创 2018-03-14 19:05:30 · 127 阅读 · 0 评论 -
Leetcode 33. Search in Rotated Sorted Array
题目链接问题描述Suppose an array sorted in ascending order 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 fo...原创 2018-05-03 10:55:19 · 108 阅读 · 0 评论 -
Leetcode 338. Counting Bits
题目链接问题描述Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5...原创 2018-04-25 15:42:42 · 175 阅读 · 0 评论 -
Leetcode 31. Next Permutation
题目链接问题描述Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest poss...原创 2018-04-26 14:52:26 · 134 阅读 · 0 评论 -
Leetcode 39. Combination Sum
题目链接问题描述Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same ...原创 2018-05-10 21:18:08 · 129 阅读 · 0 评论 -
Leetcode 40. Combination Sum II
题目链接问题描述Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidat...原创 2018-05-11 13:55:49 · 136 阅读 · 0 评论 -
Leetcode 46. Permutations
题目链接问题描述Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]解题思路这是求一个数组的全排列。使用D...原创 2018-05-12 12:56:14 · 129 阅读 · 0 评论 -
Leetcode 47. Permutations II
题目链接问题描述Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]解题思路与Leetcode 46类似,求一个数组的...原创 2018-05-14 15:01:17 · 163 阅读 · 0 评论 -
Leetcode 34. Search for a Range
题目链接问题描述Given an array of integers nums sorted in ascending order, 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...原创 2018-05-08 16:31:56 · 173 阅读 · 0 评论 -
Leetcode 357. Count Numbers with Unique Digits
题目链接问题描述Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x <...原创 2018-05-16 13:34:52 · 163 阅读 · 0 评论 -
Leetcode 343. Integer Break
题目链接问题描述Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2,...原创 2018-05-16 14:00:41 · 112 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.213 House Robber II
题目链接问题描述After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this pl原创 2017-12-29 12:06:51 · 252 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.198 House Robber
题目链接问题描述You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of the原创 2017-12-29 12:01:29 · 255 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.17 Letter Combinations of a Phone Number
题目链接问题描述Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given be原创 2017-12-29 11:33:46 · 202 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.23 Merge k Sorted Lists
题目链接问题描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解题思路比较容易想到的是将链表逐个进行合并,但是这样会超时。最后用到分治法,顺利通过。class Solution {原创 2017-10-19 16:33:03 · 208 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.653 Two Sum IV - Input is a BST
题目链接问题描述Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input:原创 2017-10-19 16:49:18 · 246 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.15 3Sum
题目链接问题描述Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solut原创 2017-12-28 22:34:52 · 255 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.16 3Sum Closest
题目链接问题描述Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each原创 2017-12-28 22:49:28 · 217 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.18 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 targe原创 2017-12-28 22:58:01 · 304 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.62 Unique Paths
题目链接问题描述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原创 2017-12-28 23:11:16 · 242 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.63 Unique Paths II
题目链接问题描述Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and原创 2017-12-28 23:36:45 · 276 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.98 Validate Binary Search Tree
题目链接问题描述Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys les原创 2017-12-28 23:58:15 · 197 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.64 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原创 2017-12-29 10:09:08 · 210 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.12 Integer to Roman
题目链接问题描述Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解题思路将1000,900,500,400,100,90,50,40,10,9,5,4,1与对应的罗马数字用ma原创 2017-12-29 10:17:51 · 169 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.258 Add Digits
题目链接问题描述Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 +原创 2017-12-29 10:27:36 · 276 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.670 Maximum Swap
题目链接问题描述Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.Example 1:Input: 2原创 2017-12-29 10:39:33 · 223 阅读 · 0 评论 -
算法分析与设计——LeetCode Problem.99 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 pretty straight原创 2017-12-29 11:22:08 · 181 阅读 · 0 评论 -
二叉树的前序、中序、后序非递归遍历
二叉树的数据结构如下:typedef struct TreeNode { int val; TreeNode* left; //左孩子 TreeNode* right; //右孩子 TreeNode(int x) : val(x), left(NULL), right(NULL) {}}; 对于前序遍历,遍历访问节点处理规则如下...原创 2019-03-04 12:37:48 · 289 阅读 · 0 评论