自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 证明题8.3,8.12

8.3 STINGY SAT is the following problem: given a set of clauses(each a disjunction of literals) ans an integer k, find a satisfying assignment in which at most k variables are true, if such an assignme

2017-07-05 09:49:28 364

原创 8道算法机考模拟题

1000、函数求值定义超级和函数F如下: F(0, n) = n,对于所有的正整数n.. F(k, n) = F(k – 1, 1) + F(k – 1, 2) + … + F(k – 1, n),对于所有的正整数k和n.例1:F(1, 3) = 6 例2:F(2, 3) = 10 例3:F(10, 10) = 167960请实现下面Solution类中计算F(k, n)的函数(1 <= k

2017-06-26 20:50:41 444

原创 【LeetCode】215. Kth Largest Element in an Array找第K大的元素

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3,2,1,5,6,4] and k = 2, return 5.最基本的解法

2017-06-26 19:59:24 262

原创 【LeetCode】152. Maximum Product Subarray最大连续子数组乘积

问题描述Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest p

2017-06-23 19:58:50 218

原创 【LeetCode】122. Best Time to Buy and Sell Stock II

问题描述股票交易。数组第i个元素表示第i天股票的价格,整个过程能交易多次,但是卖出之前必须保证有买入。设计一个算法寻找最大收益。知道了价格走势,只要后一天比前一天价格高,我就交易。纯赚的做法。class Solution {public: int maxProfit(vector<int>& prices) { int result=0; for(int i

2017-06-22 21:19:35 184

原创 【LeetCode】121. Best Time to Buy and Sell Stock

问题描述股票交易。数组第i个元素表示第i天股票的价格,整个过程只能买一次和卖一次,设计一个算法寻找最大收益。例1: Input: [7, 1, 5, 3, 6, 4] Output: 5 只能先买进才能卖出,所以最大收益为6-1=5,而不是7-1=6。例2: Input: [7, 6, 4, 3, 1] Output: 0贪心。其实就是找一个数组里面的最大差值j-i,保证i//但是这个方法

2017-06-22 19:47:21 222

原创 【LeetCode】312. Burst Balloons爆破气球得到最大金币数

问题描述给定n个气球,每个气球对应一个编号,用数组nums[0…n-1]存放,打爆一个气球能够获得金币数:nums[left] * nums[i] * nums[right],然后这个数被移除,left和right变为相邻。求能够获得的最多的金币数量。 注:①假设nums[-1] = nums[n] = 1 ② 0 ≤ n ≤ 500, 0 ≤ nums[i] ≤ 100例:Given [3,

2017-06-22 14:49:38 472

原创 【LeetCode】72. 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 permitted on a word:a

2017-06-18 20:50:05 452

原创 【LeetCode】455. Assign Cookies贪心寻找最大解

问题描述每个孩子最多一块饼干。 gi:the greed factor of ith children sj:the size of jth cookie if sj >= gi,则能把cookie j分配给children i。 问:最多能分配到饼干的孩子数量? 例1: Input: [1,2,3], [1,1] Output: 1 只能满足小孩g[0] 例2: Input

2017-06-08 21:14:36 242

原创 【LeetCode】210. Course Schedule II

问题描述在207.Course Schedule问题的基础上,求出能够完成所有课程的其中一种可能的顺序方案,如果不存在,则返回空数组。问题就变成:如何按照post值递减来保存节点。class Solution {public: //1、设置计步器,全局变量 int count = 0; vector<int> findOrder(int numCourses, vector<

2017-06-01 18:37:39 192

原创 【LeetCode】207. Course Schedule判断有向图是否有环

1、问题描述输入:n, [[1,0], [2,1], …., [n, n-1], [0,1], …..],假设没有重复的边 n表示总共0~n-1门课程,即n个节点 [1,0]表示先上课程0,才能上课程1,即0→1有一条有向边 输出:能否完成所有课程,即无环true/有环false2、思路DFS。 除了树边,假设存在一条边v→u,则有如下性质: 1. pre(u) < pre(v),pos

2017-05-29 10:03:56 1189

原创 【LeetCode】516. Longest Palindromic Subsequence最长回文子序列(非连续)

Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000. Input: “bbbab” Output: 4 一种可能的最长子序列为”bbbb”.

2017-05-11 22:04:53 462

原创 【LeetCode】2.Add Two Numbers两个单链表相加

You are given two non-empty linked lists(非空链表) representing two non-negative integers(非负整数). The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers a

2017-05-09 01:54:53 1513

转载 虚函数和纯虚函数的区别

首先:强调一个概念定义一个函数为虚函数,不代表函数为不被实现的函数。定义他为虚函数是为了允许用基类的指针来调用子类的这个函数。定义一个函数为纯虚函数,才代表函数没有被实现。定义纯虚函数是为了实现一个接口,起到一个规范的作用,规范继承这个类的程序员必须实现这个函数。1、简介假设我们有下面的类层次:[cpp] view plain copy print?class A  {  public

2017-05-04 22:06:18 225

转载 TCP 长连接/短连接 三次握手/四次握手

建立TCP需要三次握手才能建立,而断开连接则需要四次握手。整个过程如下图所示:先来看看如何建立连接的。首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资源。Client端接收到ACK报文后也向Server段发生ACK报文,并分配资源,这样TCP连接就建立了。那如何断开连接呢?简单的过程如下:在TCP层,有个FLAGS字段,这个字段有以下几个标识:SYN,

2017-05-03 10:49:35 1095

原创 【笔试】百度编程题

百度2017春招笔试真题编程题集合1、找第三便宜的帽子。#include <iostream>#include <vector>#include <algorithm>using namespace std;int main() { int n; cin >> n; vector<int> result; int price; for (int i =

2017-04-30 12:08:42 689

原创 【LeetCode】300.Longest Increasing Subsequence最长递增子序列LIS

给定数组 [10, 9, 2, 5, 3, 7, 101, 18],其中一个最长递增子序列(不需要连续)为[2, 3, 7, 101] ,length为4。因为最长子序列不一定唯一,所以我们只需要返回长度值。【解题思路】老师上课讲的经典的一道动态规划。而且有两种方法:O(n2)和O(nlogn)。(1)方法1:常规思路,O(n2)f[i]:表示以元素a[i]为结尾的最长递增子序列的

2017-04-26 01:11:02 228

原创 【LeetCode】53.Maximum Subarray最大连续子序列和

给定数组 [-2,1,-3,4,-1,2,1,-5,4],子序列[4,-1,2,1] 有最大和6。【解题思路】老师上课讲的经典的一道动态规划。f[i]:表示以元素ai为结尾的子序列的最大和。当i=0,f[i]=ai当i>0,如果f[i-1]如果f[i-1]>=0,f[i]=f[i-1]+ai答案:max{f[0],f[1],....,f[n]}。T(n)=O

2017-04-23 02:17:04 319

原创 Map

map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字key,每个关键字只能在map中出现一次,第二个可能称为该关键字的值value)的数据处理能力,由于这个特性,它完成有可能在处理一对一数据时,在编程上提供快速通道。map内部数据的组织——map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后面会见识到

2017-03-31 16:38:03 180

原创 【LeetCode】No.55 Jump Game

【原题】Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents yourmaximum jump length at that position. Determine

2017-03-31 16:25:25 173

原创 【LeetCode】No.34 Search for a Range

【原题】Given an array of integers 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 th

2017-03-24 17:17:41 217

原创 【LeetCode】No.257 Binary Tree Paths

【原题】Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree:  1 /   \2     3\  5All root-to-leaf paths are: ["1->2->5", "1->3"]【翻译】要求输出一个

2017-03-18 18:26:40 154

原创 【LeetCode】No.53 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

2017-03-13 22:07:06 259

原创 【LeetCode】No.169 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 ele

2017-03-05 00:28:03 188

原创 【LeetCode】No.70 Climbing Stairs

【原题】Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the targe

2017-02-25 23:42:37 312

原创 【LeetCode】No.1 Two Sum

【原题】Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the targe

2017-02-25 14:48:37 201

原创 Welcome

Welcome

2017-02-23 19:22:24 251

空空如也

空空如也

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

TA关注的人

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