摘要:
/* 题目: 寻找递增数组0~n-1中缺失的数字。 */ /* 思路: 变形二分法。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace
阅读全文
posted @ 2019-12-23 21:33
笨宝宝
阅读(231)
推荐(0)
摘要:
/* 题目: 统计一个数字在排序数组中出现的次数。 */ /* 思路: 1、从前往后遍历,时间复杂度O(n)。 2、二分查找到目标数字target,向前向后遍历,时间复杂度O(n)。 3、利用二分法,递归找到数字出现的第一个位置和最后一个位置,时间复杂度O(logn)。 */ #include<io
阅读全文
posted @ 2019-12-23 20:49
笨宝宝
阅读(189)
推荐(0)
摘要:
#include<iostream> #include<cstdlib> #include<stack> #include<string> #include<vector> using namespace std; void HeapAdjust(vector<int> &A, int beginI
阅读全文
posted @ 2019-12-21 18:39
笨宝宝
阅读(144)
推荐(0)
摘要:
/* 题目: 求两个链表的第一个公共节点。 */ /* 思路: 见代码。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; s
阅读全文
posted @ 2019-12-20 21:11
笨宝宝
阅读(142)
推荐(0)
摘要:
/* 题目: 求给定数组的逆序对数。 */ /* 思路: 归并排序。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; int
阅读全文
posted @ 2019-12-20 20:35
笨宝宝
阅读(167)
推荐(0)
摘要:
#include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; void merge(int A[], int left,int mid,int
阅读全文
posted @ 2019-12-18 20:48
笨宝宝
阅读(103)
推荐(0)
摘要:
#include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; int partition(vector<int> &A, int begin,i
阅读全文
posted @ 2019-12-17 22:29
笨宝宝
阅读(133)
推荐(0)
摘要:
/* 题目: 求从1开始的第n个丑数。 */ /* 思路: 按顺序列出各个丑数。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace st
阅读全文
posted @ 2019-12-17 21:19
笨宝宝
阅读(197)
推荐(0)
摘要:
/* 题目: 求字符串第一个只出现一次的字符。 */ /* 思路: 使用map遍历两次,第一次计数,第二次找到计数为1的第一个字符。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #inclu
阅读全文
posted @ 2019-12-17 19:17
笨宝宝
阅读(129)
推荐(0)
摘要:
/* 题目: 最长不含重复字符的子字符串。 */ /* 思路: f(i) = f(i-1) + 1,(未出现过当前字符,distance > f(i-1) distance,当前字符和上一次出现该字符的距离 */ #include<iostream> #include<cstring> #inclu
阅读全文
posted @ 2019-12-16 21:12
笨宝宝
阅读(205)
推荐(0)