自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【算法刷题】leetcode subsets ii

Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order. The solution set must not contain duplicate...

2018-08-30 15:10:22 209

原创 【算法刷题】leetcode restore-ip-addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order does no...

2018-08-30 15:07:59 263

原创 【算法刷题】leetcode Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)...

2018-08-14 15:39:58 191

原创 【算法刷题】leetcode Maximal-Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 思路参考  blog  int maximalRectangle(vector<vector<char> > &am...

2018-08-13 12:16:41 191

原创 【算法刷题】 leetcode Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each...

2018-07-24 09:32:41 216

原创 【算法刷题】leetcode longest-consecutive- sequence

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. ...

2018-07-22 17:47:28 197

原创 【算法刷题】leetcode surrounded region

Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X XX O O XX X O XX O X...

2018-07-22 17:07:25 178

原创 【算法刷题】leetcode 分割回文串

Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s ="aab",Return [ ["aa","b"], ["a"...

2018-07-15 16:09:04 485

原创 【算法刷题】 单链表的快排和归并排序

快排: struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; void swap(ListNode *l, ListNode *r) { int temp = l->val; l->val = r-&...

2018-07-14 18:18:50 334

原创 【算法刷题】leetcode gas-station

There are N gas stations along a circular route, where the amount of gas at station iisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from station i to its next s...

2018-07-11 22:06:55 187

原创 【算法刷题】N皇后问题

主要思想就是递归回溯,一行一行的加,每次确保前边的都满足要求,因此,新加入的一行只需与遍历前边已加入的行,是否满足要求即可//N-Queens//一行一行放置使其不冲突 递归回溯 //检查最后一行的皇后,和前边行的是否冲突 bool check(int row, vector<int> Queen) { for (int i = 0; i < row; ++i)...

2018-07-11 10:21:45 353

原创 【算法刷题】leetcode word ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word must ...

2018-07-07 19:58:54 212

原创 【算法刷题】leetcode 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 your maximum jump length at that position.Determine ...

2018-07-07 15:31:06 231

原创 【算法刷题】leetcode Reverse digits of an integer.

Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have alrea...

2018-07-04 20:55:11 229

原创 【算法刷题】leetcode reorder-list

Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,...

2018-07-04 19:26:43 160

原创 【算法刷题】leetcode word-break

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens ="leetcode",dict =["leet", "code"]....

2018-07-04 16:06:56 177

原创 【算法刷题】leetcode Candy

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy....

2018-07-01 20:33:52 371

原创 【算法刷题】8皇后问题

利用一个8个元素数组:queen[i]表示第i行的皇后所在列数;8个元素只能从0-7中选择,每个只能一次,这就保证了皇后不处在同一列或同一行,对于不处对角:任意两行的皇后i、j,不在对角满足|i-j|!=|queen[i]-queen[j]|由此,可解题:queen数组的全排列,对于全排列中每一个可能性,判断不在对角的条件//8皇后问题//全排列+逐个判断int g_number = 0;v...

2018-06-20 20:03:49 261

原创 【算法刷题】字符串的组合(非排列)

递归的思想:n个字符里取出m个从头扫描字符串的第一个字符。针对第一个字符,有两种选择:要么取第一个,剩下n-1个取m-1个,要么第一不取,剩下n-1个中取m个,递归实现//n个字符里取出m个,递归实现//要么取第一个,剩下n-1个取m-1个,要么第一不取,剩下n-1个中取m个void Combination(char* str, int length, vector<char>&a...

2018-06-19 11:39:13 217

原创 【C++总结记载】类对象、继承、虚继承、虚函数表

关于虚函数表,可见博客    传送    ,但是要注意,一般被继承的第一个基类的虚函数表合并至子类的虚函数表,(基类的虚函数在前,除非有虚函数覆盖,子类的虚函数在后)主要讲了在无虚继承情况下各种情况的虚函数表的情况,因此,就牵扯到了类的大小的问题:1)对于一个空类,sizeof=1;2)静态成员不属于类大小中,且成员函数也不属于类大小中3)类与继承情况下类的大小:情况一: ...

2018-06-18 20:01:25 960

原创 【算法刷题】子序列个数

子序列的定义:对于一个序列a=a[1],a[2],......a[n],则非空序列a'=a[p1],a[p2]......a[pm]为a的一个子序列,其中1<=p1<p2<.....<pm<=n。例如:4,14,2,3和14,1,2,3都为4,13,14,1,2,3的子序列。 对于给出序列a,有些子序列可能是相同的,这里只算做1个,要求输出a的不同子序列的数量。解题:...

2018-06-18 11:59:17 1076

原创 【算法刷题】字符串编辑距离

源串到目的串:只能删除、增加、替换动态规划:dp[i][j]    s[0....i] ->t[0...j]的最小编辑距离字符串对其:状态方程:dp[i][j] = min{dp[i-1][j]+1,dp[i][j-1]+1,dp[i][j]=dp[i-1][j-1]+(s[i]==t[j]?0:1)}#include <iostream>#include <string...

2018-06-17 22:27:21 229

原创 【算法刷题】CodeM2018 初赛A轮 下棋

CodeM2018 初赛A轮  下棋   第二题[编程|1000分] 下棋 时间限制:C/C++ 1秒,其他语言 2秒 空间限制:C/C++ 262144K,其他语言 524288K 64bit IO Format: %lld 题目描述 有一个1*n的棋盘,上面有若干个棋子,一个格子上可能有多个棋子。 你每次操作是先选择一个棋子,然后选择以下两个操作中的一个: (1) 若该棋...

2018-06-15 14:59:11 447

转载 【TCP/IP】tcp中的time_wait

1.time_wait状态是什么简单来说:time_wait状态是四次挥手中server向client发送FIN终止连接后进入的状态。下图为tcp四次挥手过程  能够看到time_wait状态存在于client收到serverFin并返回ack包时的状态 当处于time_wait状态时,我们无法创建新的连接,由于port被占用。2.为什么会有time_wait状态time_wait存在的原因有两点...

2018-06-15 12:34:02 178

原创 【算法刷题】找出数组中出现次数大于N/K的所有元素

数组中出现次数超过一半(可实现时间复杂度o(n),空间复杂度o(1))的进阶版鸽巢原理:出现次数大于N/K的元素的个数至多为(M-1)个思路:每次从数组中删除k个不同的元素,直到不能再删了为止。那么最后数组中剩余的元素就是候选元素。因此  可建立一个k长度的map记录从数组中待消的元素,例如数组a={4,3,3,9,4,2,1,4,3,4,9,2}  N=12,k=3 ,则每次应该删3个数,依次遍...

2018-06-10 16:57:18 2447

转载 【算法刷题】字符串中出现的相同且长度最长的字符串

以左和右查找子串是否出现位置相同,不同说明存在重复子串#include<iostream>#include<string>using namespace std;pair<int, string> longestsubstr(const string & str);int main(){ string s = "aaaaa"; pair&...

2018-06-03 22:29:47 462

原创 【算法刷题】美团CodeM 2018资格赛

小美和小团最近沉迷可乐。可供TA们选择的可乐共有k种,比如可口可乐、零度可乐等等,每种可乐会带给小美和小团不同的快乐程度。TA们一共要买n瓶可乐,每种可乐可以买无限多瓶,小美会随机挑选其中的m瓶喝,剩下的n-m瓶小团喝。请问应该如何购买可乐,使得小美和小团得到的快乐程度的和的期望值最大?现在请求出购买可乐的方案。输入描述:第一行三个整数n,m,k分别表示要买的可乐数、小美喝的可乐数以及可供选择的可...

2018-06-03 20:39:34 1027

原创 【算法刷题】 最长单调子序列

子序列在原序列中可以是不连续的动态规划求解://时间复杂度   n*n//令c[i]表示:在a[0->i]中,当以a[i]为单调递增子序列最后一个元素时,所得最长单调递增子序列的长度。状态转移方程:c[0]=1;c[i]=max{1,c[j]+1}    a[j]<a[i]&&j<i;int LongestIncr(int X[], int n, int c[],...

2018-06-03 20:28:07 662

原创 【算法刷题】一个字符串中连续出现次数最多的子串

//字符串中连续出现次数最多的子串//利用后缀数组后缀数组是一种数据结构,对一个字符串生成相应的后缀数组后,然后再排序,排完序依次检测相邻的两个字符串的开头公共部分。//这样的时间复杂度为:总的时间复杂度是 O(N^2*logN),//后缀数组,每一行比上一行少一个,跳行就可出现少2个、3个……//第一趟:(一个长度的子串)第一行a与第二行第一个b比较是否相等,不等 (若相等则继续在第二行后取长度...

2018-06-03 20:18:13 3790

空空如也

空空如也

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

TA关注的人

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