自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(11)
  • 收藏
  • 关注

原创 Partition Equal Subset Sum解题报告

题目链接https://leetcode.com/problems/partition-equal-subset-sum/description/ 题目描述如下Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such th

2017-12-17 17:57:06 213

原创 Combination Sum的递归解法

题目链接:https://leetcode.com/problems/combination-sum/description/ 题意大概是: 给出一个候选数组(表示一个一个集合即元素不重复)和一个目标整数,从候选数组中选出和为目标数的组合(元素可重复)。 有点像排列组合,可以用递归来解决class Solution {public: vector<vector<int> > comb

2017-12-10 22:18:08 326

原创 Longest Palindromic Substring

题目链接Longest Palindromic Substring 这道题是求最大回文子串。 用动态规划来解决的话,其中一个状态转移方程为// dp(i,j)表示字符串s的子串s[i,j]是否为回文串// 对于j > i - 1if s[i] == s[j] then dp(i,j) = dp(i+1, j-1)// 对j == i - 1 或 j == i处理比较简单// 在处理过程中

2017-12-03 14:49:14 116

原创 Target Sum

题目链接 题目描述 比较直接的想法是通过递归来做 实现代码如下class Solution {public: int findTargetSumWays(vector<int>& nums, int S) { return sumNum(nums,nums.size(),S); } int sumNum(vector<int> &nums, int

2017-11-12 23:18:39 142

原创 Maximum Length of Repeated Subarray解题报告

题目链接Maximum Length of Repeated Subarray 题目描述:Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Outp

2017-11-05 10:19:21 192

原创 Edit Distance 解题报告

题目链接 这是道比较经典的动态规划题。 状态转移方程:对于字符串x,y,编辑距离E(i,j)为E(i,j) = min(1 + E(i-1,j), 1 + E(i,j-1), diff(i,j) + E(i-1,j-1))diff(i,j) = if x[i] == y[j] then 0 else 1初始状态:E(0,i) = E(j,0) = 0伪代码是for i = 0,1,2,...

2017-10-29 11:06:53 156

原创 Median of sorted arrays解题报告

题目链接 题意:找出两个有序整数数组的中位数,要求时间复杂度是O(log(m+n)) Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0Example 2:nums1 = [1, 2]nums2 = [3, 4]The median is (2 + 3)/2 = 2.5求中位数,也即求某个具体位置的值,所以可以转化为

2017-10-19 10:59:34 142

原创 Longest Valid Parentheses

题目链接为Longest Valid Parentheses 题目描述为: Given a string containing just the characters ‘(’ and ‘)’, find the length of the >longest valid (well-formed) parentheses substring. For “(()”, the longes

2017-10-03 22:30:44 105

原创 01 Matrix解题报告

这是一道中等题,题目链接为:01 Matrix题目描述:现有一个只包含0和1的矩阵,找出每个元素最近的0的距离,并以矩阵的形式输出相邻的元素之间的距离为1,相邻指的是上下左右,不包括对角线样例1input:0 0 00 1 00 0 0output:0 0 00 1 00 0 0样例二:input:0 0 00 1 01 1 1output:0 0 00 1 0

2017-09-25 15:21:55 400

原创 Number of Longest Increasing Subsequence 解题报告

题目链接为:Number of Longest Increasing Subsequence 题目要求很简单:给出一个无序的整数数组,找出最长递增子序列的个数。并给了两个样例: 样例1Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [1, 3

2017-09-16 14:25:40 226

原创 Kth Largest Element in an Array解题报告

Kth Largest Element in an Array解题报告这是道中等题,不难,一般都能Accepted,关键是看能不能在时间复杂度上面做优化。 首先我能想到的是用选择排序的思想,由大到小排序,一直到排到第K大个就停止并返回,这样对于n个元素的数组,平均时间复杂度为O(n2)O(n^2),下面是C++代码的实现:class Solution {public: int findK

2017-09-10 20:58:15 300

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除