06 2018 档案

摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target valu 阅读全文
posted @ 2018-06-26 22:37 小小Cv 阅读(101) 评论(0) 推荐(0)
摘要:假设你对KMP算法有了解但感到困惑,本文不解释KMP算法的定义。 之前查找资料的时候看到长篇大论的,所以看都不想看,结果自己想表达出来时。。。也变得长篇大论了 详细说一下KMP算法,刚看到的时候一头雾水,想不明白lps[]这个数组的作用,以及实现。 在说明lps[]之前先说明一下最长的相同的前缀后缀 阅读全文
posted @ 2018-06-23 20:10 小小Cv 阅读(265) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public: 3 int removeDuplicates(vector& nums) { 4 if(nums.empty()) 5 return 0; 6 int i = 0; 7 for(int j = 1; j < nums.size(); j++) ... 阅读全文
posted @ 2018-06-21 19:53 小小Cv 阅读(107) 评论(0) 推荐(0)
摘要:Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. 阅读全文
posted @ 2018-06-19 10:35 小小Cv 阅读(155) 评论(0) 推荐(0)
摘要:快速排序是比较常用的到的一个算法,也使用了分治思想。 快排主要找到一个分界点partition,使得[left,partition-1]的所有元素小于或等于[partition],使得[partition+1,right]的所有元素大于[partition] 此时已经算排好一个位置(partitio 阅读全文
posted @ 2018-06-14 19:29 小小Cv 阅读(150) 评论(0) 推荐(0)
摘要:= = 因为用的是数组实现,所以在size比较大的时候会内存溢出 阅读全文
posted @ 2018-06-13 22:49 小小Cv 阅读(135) 评论(0) 推荐(0)
摘要:1 struct A 2 { 3 int maxright; // 记录右边最大子数组的下标 4 int maxleft; // 记录左边最大子数组的下标 5 int sum; // 记录数组下标maxleft--maxright的元素和 6 }; 7 8 void Solution... 阅读全文
posted @ 2018-06-12 23:50 小小Cv 阅读(154) 评论(0) 推荐(0)
摘要:1 #include 2 3 struct input_iterator_tag {}; 4 struct output_iterator_tag {}; 5 struct forward_iterator_tag : public input_iterator_tag {}; 6 struct bidirectional_iterator_tag : public ... 阅读全文
posted @ 2018-06-12 18:08 小小Cv 阅读(174) 评论(0) 推荐(0)
摘要:分治模式在每层递归时都有三个步骤: 一:分解原问题为若干子问题,这些子问题都是原问题的规模较小的实例 二:解决这些子问题,递归地求解各个子问题。 三:合并这些子问题的解,使成为原问题的解 比如上述算法,将对一个数组排序的问题不断切分为更小的排序问题,直到最后(left<right),此时所有实例都是 阅读全文
posted @ 2018-06-12 18:02 小小Cv 阅读(241) 评论(0) 推荐(0)
摘要:每次选出最小的数将其放在vec[i] void Solution::selectSort(vector<int>& vec){ for(int i = 0; i < vec.size() - 1; i++) { int key = i; // 记录最小数的下标 for(int j = i+1; j 阅读全文
posted @ 2018-06-11 23:21 小小Cv 阅读(99) 评论(0) 推荐(0)
摘要:solution.h: #include <vector>using namespace std;class Solution{public: void insertSort(vector<int>& vec);}; solution.cpp: #include "solution.h"void S 阅读全文
posted @ 2018-06-11 22:42 小小Cv 阅读(111) 评论(0) 推荐(0)
摘要:计划每天能更新至少一道算法题... 分三个文件:solution.h,solution.cpp,test.cpp 顾名思义,solution.* 用于算法的相关实现,test.cpp用于相关测试 阅读全文
posted @ 2018-06-11 22:38 小小Cv 阅读(96) 评论(0) 推荐(0)
摘要:simple_alloc只是对配置器的简单包装 代码如下: 阅读全文
posted @ 2018-06-11 14:47 小小Cv 阅读(601) 评论(0) 推荐(0)
摘要:本文不考虑异常处理情况。 STL的第二级配置器是默认使用的配置器,第一级配置器只是简单的调用malloc(),free(),realloc()等函数,并没有真正意义上对内存进行管理 STL的第二级配置器相对较为复杂,利用了链表的形式管理16种内存大小不同的区块。由于链表的存在,当使用内存不再需要时, 阅读全文
posted @ 2018-06-11 14:41 小小Cv 阅读(358) 评论(0) 推荐(0)
摘要:考虑到复杂度问题,没有实现异常处理. 学习STL主要目的之一是为了学习内存管理 阅读全文
posted @ 2018-06-11 14:28 小小Cv 阅读(254) 评论(0) 推荐(0)