STL(四)——deque

Deque概述 vector是单向开口的连续线性空间,dequeue则是一种双向开口的局部连续线性空间。deque和vector最大的差异在于,deque允许常数时间内对头部进行插入或移除,二在于deque没有容量的观念,因为它是动态地以分段连续空间组合而成,随时可以增加一段新空间并连接起来。虽然deque也提供random access iterator,但迭代器并不像vector那样是普通指...
分类: 其他 发布时间: 09-25 23:12 阅读次数: 0

STL(五)——set/map/multiset/multimap概述

Set概述 set的特性是,所有元素都会根据元素的键值自动被排序。set元素不允许两个元素有相同的键值。我们不能通过set的迭代器改变set的元素值,因为set的元素值关系到set的排列。而且set和list有相似的性质:当对它进行insert或者erase操作的时候,操作之前的所有迭代器和操作之后的其他迭代器,都不会失效,当然,被删除的迭代器会失效。 因为set是用rb-tree实现的,所以...
分类: 其他 发布时间: 09-25 23:12 阅读次数: 0

STL(六)——hashtable(一):哈希介绍与部分STL实现

hashtable概述 hashtable是一种以空间换时间的数据结构,哈希函数让hashtable在插入、删除、搜索等操作上有“常数平均时间”的表现,因此很受欢迎。   hashtable的冲突解决 使用hash function会带来一个问题:可能有不同的元素被映射到相同的位置。有几种解决办法,我们一一介绍。 一. 线性探测(linear——probing) 当hash funct...
分类: 其他 发布时间: 09-25 23:12 阅读次数: 0

STL(七)——hashtable(二):哈希函数

介绍STL里hashtable的使用 例子: #include<hash_set> #include<iostream> using namespace std; int main() { hashtable< int, //Value类型 hash<int>, //键值类型 ...
分类: 其他 发布时间: 09-25 23:12 阅读次数: 0

STL(八)——算法(Algorithm)(一)

算法概观 STL算法是将最常被运用的算法规范出来,其涵盖的区间有可能在每五年一次的C++标准委员会中不断增订。广义而言,我们所写的每个程序都是一个算法,其中的每个函数也都是一个算法。STL收录了许多算法,包括排序,查找,排列组合等等的算法。STL为这些算法提供能泛化使用的版本。但要注意的是,特定的算法往往搭配特定的数据结构,例如RB-tree便是为了解决查找问题而提出的,本篇讨论的算法大多是独立...
分类: 其他 发布时间: 09-25 23:11 阅读次数: 0

STL(九)——算法(Algorithm)(二):copy

STL包含众多算法,不过很多算法实现其实很简单,看源码即可理解。但也有部分简单的函数,实现版本做了很多工作来加快效率,copy函数就是一个例子。我们挑sgi stl实现的copy函数作为例子谈一谈。   概述 copy函数是调用比较频繁的函数,由于copy进行的是复制操作,而复制操作不外乎运用赋值运算符或复制构造函数实现,但有但元素拥有trivial assignment operato...
分类: 其他 发布时间: 09-25 23:11 阅读次数: 0

STL(十)——remove算法

remove函数 remove函数用于移除[first,last)之中所有与value相等都元素。这一算法并不真正从容器中删除元素,而是将每一个不与value相等的元素轮番赋值给first之后的空间。返回值forearditerator标示出重新整理后的最后元素的下一个位置。例如序列{0,1,0,2,0,3,0,4},如果我们执行remove(),希望移除所有0值元素,执行结果将是{1,2,3,...
分类: 其他 发布时间: 09-25 23:11 阅读次数: 0

STL(十一)——sort

STL提供的各种算法里,sort()是最复杂庞大的一个。这个算法接受两个RandomAccessIterators(随机存取迭代器),然后将区间内的所有元素以渐增方式从小到大排序。 STL的sort算法,数据量大时采用Quick Sort,分段递归排序。一旦分段后的数据量小于某个门槛,为避免Quick Sort的递归调用带来过大的额外负荷(overhead),就改用插入排序。如果递归层次太深,还...
分类: 其他 发布时间: 09-25 23:11 阅读次数: 0

LeetCode——461.Hamming Distance

问题:                     这道问题实际上是求两个数里1不一样的位数。我一开始的答案是如下: class Solution { public: int hammingDistance(int x, int y) { int flag = 1; int count = 0; for(int i ...
分类: 其他 发布时间: 09-25 23:10 阅读次数: 0

LeetCode——Peak Index in a Mountain Array(852)

Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ....
分类: 其他 发布时间: 09-25 23:10 阅读次数: 0

Linux程序设计(一)——静态库

静态库概述(度娘一波) 静态库,也称归档文件(archive),是指在我们的应用中,有一些公共代码是需要反复使用,就把这些代码编译为“库”文件;在链接步骤中,连接器将从库文件取得所需的代码,复制到生成的可执行文件中的这种库。 程序编译一般需经预处理、编译、汇编和链接几个步骤。静态库特点是可执行文件中包含了库代码的一份完整拷贝;缺点就是被多次使用就会有多份冗余拷贝。 静态库(*.a)(这里的....
分类: 其他 发布时间: 09-25 23:10 阅读次数: 0

LeetCode——Array Partition I(561)

Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as poss...
分类: 其他 发布时间: 09-25 23:10 阅读次数: 0

Leetcode——Sort Array By Parity(905)(持续更新)

Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array that satisfies this conditi...
分类: 其他 发布时间: 09-25 23:09 阅读次数: 0

LeetCode——Self Dividing Numbers(728)

A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Also, a self-dividin...
分类: 其他 发布时间: 09-25 23:09 阅读次数: 0

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...
分类: 其他 发布时间: 09-25 23:09 阅读次数: 0

LeetCode——work-break-ii(140)

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible ...
分类: 其他 发布时间: 09-25 23:09 阅读次数: 0

LeetCode——Palindrome Partitioning II(132)

Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. Example: Input: "aab" Output: 1 Explana...
分类: 其他 发布时间: 09-25 23:08 阅读次数: 0

LeetCode——Triangle(120)

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5...
分类: 其他 发布时间: 09-25 23:08 阅读次数: 0

LeetCode——Distinct Subsequences(115)

Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original string by deleting some (ca...
分类: 其他 发布时间: 09-25 23:08 阅读次数: 0

这届互联网公司月饼:阿里卡哇伊,百度酷炫风,京东乾隆审美……

哈喽程序员朋友们大家好哇,今天就正式开启中秋小长假啦,公司的月饼都发了吗? 这几天,朋友圈俨然已成为各大互联网公司的月饼 PK 战场,争奇斗艳,好不热闹。 日常,普通人拼车拼房拼自己,而放到各大互联网公司上,就是拼员工拼技术拼实力。 每逢佳节,普通人拼奖金拼福利拼假期,对于各大互联网公司来说,拼的就是独树一帜的创意。 在这一年一度的中秋佳节来临之际,月饼作为中秋节的福利的代表,当然是各大公司必...
分类: 编程语言 发布时间: 09-25 23:06 阅读次数: 0