![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
学习篇
chender_sysu
这个作者很懒,什么都没留下…
展开
-
LeetCode学习篇二——分治法
这星期学习了分治法,所以在leetcode上打算做一些相关的题,随便打开了一道相关算法题,题目如下: 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,原创 2016-09-11 14:25:50 · 549 阅读 · 0 评论 -
LeetCode学习篇十一——Range Sum Query - Immutable
题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1原创 2016-10-30 16:05:06 · 226 阅读 · 0 评论 -
LeetCode学习篇十三——Perfect Squares
题目:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, ret原创 2016-10-31 21:35:57 · 194 阅读 · 0 评论 -
LeetCode学习篇十四——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 them is that adjacent hou原创 2016-11-01 13:33:21 · 223 阅读 · 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.原创 2016-11-01 15:54:05 · 154 阅读 · 0 评论 -
LeetCode学习篇二十二——Decode String
题目:Given an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is gua原创 2016-11-17 00:08:16 · 208 阅读 · 0 评论 -
算法概论8.3题解
题目:吝啬SAT是这样一种问题:给定一组子句(每个子句都是其中文字的析取)和一个整数k,求一个最多有k个变量为true的满足赋值,如果这样的赋值存在的话。证明吝啬SAT问题是NP完全问题。要证明一个问题是NP完全问题,就要证明它是NP的和NP-Hard的首先证明吝啬SAT是NP的很明显,给定一组文字的赋值,我们能在多项式时间内验证该解,因此是NP的。然后证明吝啬SAT是NP-Har原创 2016-11-30 16:43:28 · 280 阅读 · 0 评论 -
算法概论8.15题解
题目:证明以下问题是NP完全问题最大公共子图输入:两个图G1=(V1,E1)和G2=(V2,E2);预算b输出:两个节点集合V1'⊆V1且V2'⊆V2,它们被移除后,将在两图中剩下至少b个节点,且图的剩余部分完全一样。首先证明该问题是NP问题给定一组解,即两个节点集合,我们可以在多项式时间内验证该解然后证明该问题是NP难问题考虑将最大独立集问题归约到最大公共子图原创 2016-11-30 17:20:35 · 473 阅读 · 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.For example:原创 2016-11-22 14:42:18 · 177 阅读 · 0 评论 -
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:原创 2016-11-22 15:01:24 · 195 阅读 · 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 of every node never differ原创 2016-11-22 15:32:35 · 307 阅读 · 0 评论 -
LeetCode学习篇二十六——Maximum Product Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest product.原创 2016-12-05 13:55:37 · 175 阅读 · 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] has原创 2016-12-05 14:22:18 · 222 阅读 · 0 评论 -
leetcode学习篇十——Is Subsequence
题目:Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string,原创 2016-10-30 11:32:12 · 165 阅读 · 0 评论 -
leetcode学习篇六——Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree:利用深度优先搜索遍历二叉树即原创 2016-10-06 20:15:09 · 176 阅读 · 0 评论 -
LeetCode学习篇二十一——Interge 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, retur原创 2016-11-09 13:59:30 · 1041 阅读 · 0 评论 -
LeetCode学习篇一——Counting Bits
LeetCode学习篇一——Counting Bits原创 2016-09-04 19:57:01 · 310 阅读 · 1 评论 -
leetcode学习篇七——Find Minimum in Rotated Sorted Array
试了一些pick one功能,随机选取了一道题,题目如下: 153. Find Minimum in Rotated Sorted Array 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}).F原创 2016-10-08 23:17:52 · 146 阅读 · 0 评论 -
leetcode学习篇三——Different Ways to Add Parentheses
看到leetcode的题有时还是会懵逼,继续做一下分治的题目,题目如下: Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid opera原创 2016-09-26 15:26:29 · 185 阅读 · 0 评论 -
LeetCode学习篇十六——Best Time to Buy and Sell Stock
题目:Say you have an array for which the i^th 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),原创 2016-11-03 23:28:46 · 148 阅读 · 0 评论 -
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 one原创 2016-11-04 00:10:42 · 153 阅读 · 0 评论 -
LeetCode学习篇十八——Best Time to Buy and Sell Stock with Cooldown
题目: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 one原创 2016-11-04 00:34:34 · 182 阅读 · 0 评论 -
LeetCode学习篇八—— Arithmetic Slices
题目:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:原创 2016-10-26 19:25:56 · 186 阅读 · 0 评论 -
LeetCode学习篇九——Coin Change
题目:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mone原创 2016-10-26 23:24:41 · 228 阅读 · 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?原创 2016-11-07 21:16:41 · 190 阅读 · 0 评论 -
LeetCode学习篇二十——Bulls and Cows
题目:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-11-07 21:21:03 · 183 阅读 · 0 评论 -
leetcode学习篇四——Majority Element
题目如下: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2016-10-06 11:30:27 · 165 阅读 · 0 评论 -
leetcode学习篇五——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 + 1 = 2. Since 2 has only one原创 2016-10-06 15:07:00 · 216 阅读 · 0 评论 -
LeetCode学习篇十二——Count Numbers with Unique Digits
题目:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, exc原创 2016-10-30 18:17:40 · 164 阅读 · 0 评论