摘要: 1 #include "000库函数.h" 2 3 //第一感觉使用回溯比较快 4 //96ms 5 6 7 class Solution { 8 public: 9 vector> combinationSum2(vector& candidates, int target) { 10 vector>R; 11 sort(cand... 阅读全文
posted @ 2019-03-20 18:59 自由之翼Az 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 1 #include "000库函数.h" 2 3 //第一感觉使用回溯比较快 4 //好激动,第一次使用回溯成功 96ms,37.1M 5 6 7 class Solution { 8 public: 9 vector> combinationSum(vector& candidates, int target) { 10 v... 阅读全文
posted @ 2019-03-20 17:35 自由之翼Az 阅读(377) 评论(0) 推荐(0) 编辑
摘要: 1 #include "000库函数.h" 2 3 4 //自解,就遍历数数 8ms 5 class Solution { 6 public: 7 string countAndSay(int n) { 8 if (n == 0)return ""; 9 string str = "1"; 10 string s; ... 阅读全文
posted @ 2019-03-19 15:32 自由之翼Az 阅读(371) 评论(0) 推荐(0) 编辑
摘要: //跟此题类似的有 Permutations 全排列,Combinations 组合项, N - Queens N皇后问题等等,//其中尤其是跟 N - Queens N皇后问题的解题思路及其相似,对于每个需要填数字的格子带入1到9,//每代入一个数字都判定其是否合法,如果合法就继续下一次递归,结束 阅读全文
posted @ 2019-03-19 15:31 自由之翼Az 阅读(359) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 //题目贼恶心,竟然没有说出A存在的规律!!!!! 7 //首先,必须要有PAT存在,且不能有其他字符 8 //其次P与T中间A的个数乘以P之前的个数==T之后的A的个数!!!!!!!!! 9 int main() { 10 ... 阅读全文
posted @ 2019-03-18 23:49 自由之翼Az 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 1 #include "000库函数.h" 2 3 //一看,没想出什么好法子,就遍历了 4 //最重要的是如何比较小九宫格的数据 5 //44ms 6 class Solution { 7 public: 8 bool isValidSudoku(vector>& board) { 9 for (int i = 0; i j; --k) 13 ... 阅读全文
posted @ 2019-03-18 22:46 自由之翼Az 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 1 #include "000库函数.h" 2 3 //第一眼,感觉没什么考虑算法的,就普通做就好了 4 //又因为是有序 的,故使用二分法最好了【别再太真爱用遍历,傻子才会一上来就遍历】 12ms 5 class Solution { 6 public: 7 int searchInsert(vector& nums, int target) { 8 ... 阅读全文
posted @ 2019-03-18 14:37 自由之翼Az 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 1 #include "000库函数.h" 2 3 //使用二分法查找到目标值的位置,然后分两边再查找出起始位置和终止位置 4 //16ms 不是严格意义上的logn的复杂度 5 class Solution { 6 public: 7 vector searchRange(vector& nums, int target) { 8 vectorv =... 阅读全文
posted @ 2019-03-17 16:45 自由之翼Az 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 1 #include "000库函数.h" 2 3 //自解 68ms 弱爆了 4 //先找到最大值,然后确定目标值在最大值的左边还是右边 5 //最后使用折中寻找法,找到目标值的位置,此方法应该满足复杂度不超过logn的要求 6 class Solution { 7 public: 8 int search(vector& nums, int ta... 阅读全文
posted @ 2019-03-17 15:28 自由之翼Az 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度。 示例 1: 示例 2: 这里我们还是借助栈来求解,需要定义个start变量来记录合法括号串的起始位置,我们遍历字符串,如果遇到左括号,则将当前下标压入栈,如果遇到右括号,如果当前栈为空,则将下一个坐标位置 阅读全文
posted @ 2019-03-16 16:56 自由之翼Az 阅读(306) 评论(0) 推荐(0) 编辑