自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 LeetCode 547. Friend Circles

There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, the

2017-07-06 13:29:44 301

原创 LeetCode 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 is trying to reach the

2017-07-06 13:08:45 151

原创 LeetCode 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 target.Note: The solution

2017-07-05 20:01:04 155

原创 8.8 精确4SAT问题

8.8 在精确的4SAT(EXACT 4SAT)问题中,输入为一组子句,每个子句都是恰好4个文字的析取,且每个变量最多在每个子句中出现一次。目标是求它的满足赋值——如果该赋值存在。证明精确的4SAT是NP-完全问题。首先,显然EXACT 4SAT同SAT问题类似,因为每一个解都可以在多项式时间内验证是否正确,所以我们可以得出EXACT 4SAT问题是NP的。然后,我们通

2017-07-05 19:29:57 289

原创 LeetCode 50. Pow(x, n)

Implement pow(x, n).根据n的取值分三种情况,n>0、n==0和n前几次提交结果为Time Limit Exceeded,改进最后ac版本如下:分治思想: x^n = x^(n/2) * x^(n/2) * x^(n%2),将x的n次方降幂为n/2,讨论n的奇偶性,如果n为奇数,则多乘一个v。class Solution { public:

2017-06-28 21:07:31 133

原创 LeetCode 112. 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:Given the below binary tree and sum

2017-06-28 19:31:26 142

原创 LeetCode 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 solution set must not contain

2017-06-28 19:14:54 160

原创 LeetCode 9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.检查一个整数是否回文根据回文数的特点 ,逆向相同,取收尾比较考虑奇数位与偶数位回文的区别,注意处理特殊情况class Solution {public: bool isPalindrome(int x) {

2017-06-28 18:09:48 129

原创 LeetCode 7. Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function s

2017-06-28 17:13:58 118

原创 LeetCode 1.Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam

2017-06-28 16:19:43 155

原创 算法机考模拟题1006.单词变换

Description对于两个只含有小写英文字母(’a’-‘z’)的单词word1和word2,你可以对word1进行以下3种操作: 1) 插入一个字母;2) 删除一个字母;3) 替换一个字母. 请计算将word1变换成word2的最少操作数. word1和word2的长度均不大于1000. 请为下面的Solution类实现解决上述问题的函数minD

2017-06-21 17:42:06 437

原创 算法机考模拟题1005.最大和

Description从数列A[0], A[1], A[2], ..., A[N-1]中选若干个数,要求相邻的数不能都选,也就是说如果选了A[i], 就不能选A[i-1]和A[i+1]. 求能选出的最大和. 1  请为下面的Solution类实现解决上述问题的函数maxSum,函数参数A是给出的数列,返回值为所求的最大和. class Solution {pub

2017-06-21 16:40:08 320

原创 算法机考模拟题1002.等价二叉树

Description两个二叉树结构相同,且对应结点的值相同,我们称这两个二叉树等价. 例如:以下两个二叉树等价        1           1       /  \         /  \      2   3       2   3而以下两个则不等价        1           1       /  \         /  \

2017-06-21 15:10:07 334

原创 算法机考模拟题1001.会议安排

DescriptionN个会议要同时举行,参会人数分别为A[0], A[1], ..., A[N-1]. 现有M个会议室,会议室可容纳人数分别为B[0], B[1], ..., B[M-1]. 当A[i] 1  请为下面的Solution类实现解决上述问题的函数assignConferenceRoom. 函数参数A和B的意义如上,返回值为最多可安排的会议数. cla

2017-06-21 15:03:23 328

原创 算法机考模拟题1000.函数求值

Description定义超级和函数F如下:F(0, n) = n,对于所有的正整数n..F(k, n) = F(k – 1, 1) + F(k – 1, 2) + … + F(k – 1, n),对于所有的正整数k和n. 请实现下面Solution类中计算F(k, n)的函数(1  class Solution {public:       int F(i

2017-06-21 14:43:43 258

空空如也

空空如也

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

TA关注的人

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