自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 分布式学习(一)

前言:最近到毕业的季节了,想着在工作前锻炼下自己阅读英文文献的能力,又对分布式有兴趣,就开了分布式的坑。国内分布式资料较少,因此参考了mit的课程:http://nil.csail.mit.edu/6.824/2015/schedule.html这门课虽然没有视频,但是给出了分布式相关的论文,并设置了5个实验(go语言),今天终于完成了lab1.有需要的同学可自取。 Lab1第...

2018-12-09 10:25:00 255

翻译 LeetCode——Maximum Binary Tree(654)

Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array. The left subtree is the maximum tree constructed f...

2018-11-01 09:57:40 164

原创 LeetCode——Trim a Binary Search Tree(669)

Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the re...

2018-10-31 15:08:18 142

原创 LeetCode——Convert Sorted Array to Binary Search Tree(108)

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...

2018-10-31 09:13:50 114

原创 LeetCode——Maximum Depth of N-ary Tree(559)

Given a n-ary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.For example, given a 3-ary tree: ...

2018-10-17 10:08:47 145

原创 LeetCode——Uncommon Words from Two Sentences(884)

We are given two sentences A and B.  (A sentence is a string of space separated words.  Each word consists only of lowercase letters.)A word is uncommon if it appears exactly once in one of the sent...

2018-10-16 22:58:14 147

原创 LeetCode——Leaf-Similar Trees(872)

Consider all the leaves of a binary tree.  From left to right order, the values of those leaves form a leaf value sequence.For example, in the given tree above, the leaf value sequence is (6, 7, 4...

2018-10-11 09:37:39 141

原创 LeetCode——sort list(148)

Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1-...

2018-10-10 10:36:42 121

原创 LeetCode——N-ary Tree Postorder Traversal(590)

Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary tree: Return its postorder traversal as: [5,6,3,2,4,1]. Note: Recursive solution is t...

2018-10-09 12:19:59 147

原创 LeetCode—— Longest Consecutive Sequence(128)

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Ex...

2018-09-27 14:00:11 136

原创 LeetCode——Merge k Sorted Lists(23)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[  1->4->5,  1->3->4,  2->6]Output: 1->1->2->3->4-...

2018-09-26 15:41:04 140

原创 LeetCode——Move Zeroes(283)

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You m...

2018-09-26 09:13:49 109

原创 LeetCode——Single Number(136)

Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...

2018-09-25 19:11:07 119

原创 LeetCode——Shortest Distance to a Character(821)

Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string.Example 1:Input: S = "loveleetcode", C = 'e'Output: [3, 2, 1...

2018-09-24 08:59:07 106

原创 LeetCode——N-ary Tree Postorder Traversal(590)

Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary tree: Return its postorder traversal as: [5,6,3,2,4,1]. 分析:典型的树遍历代码:/*// Defi...

2018-09-23 08:29:29 218

原创 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...

2018-09-19 16:58:43 150

原创 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...

2018-09-19 09:55:49 138

原创 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: 1Explana...

2018-09-18 16:17:51 158

原创 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 ...

2018-09-18 12:25:26 188

原创 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...

2018-09-17 18:55:38 213

原创 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...

2018-09-17 11:16:08 111

原创 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...

2018-09-16 17:10:14 488

原创 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...

2018-09-15 15:09:39 110

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

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

2018-09-15 12:51:15 189

原创 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] > ....

2018-09-14 15:51:57 125

原创 LeetCode——461.Hamming Distance

问题:          这道问题实际上是求两个数里1不一样的位数。我一开始的答案是如下:class Solution {public: int hammingDistance(int x, int y) { int flag = 1; int count = 0; for(int i ...

2018-09-13 17:48:40 159

原创 STL(十一)——sort

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

2018-09-13 15:30:17 143

原创 STL(十)——remove算法

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

2018-09-13 09:45:53 346

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

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

2018-09-12 11:31:32 212

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

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

2018-09-11 15:07:03 171

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

介绍STL里hashtable的使用例子:#include<hash_set>#include<iostream>using namespace std;int main(){ hashtable< int, //Value类型 hash<int>, //键值类型 ...

2018-09-11 10:04:15 528

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

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

2018-09-10 16:07:51 327

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

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

2018-09-07 11:08:39 250

原创 STL(四)——deque

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

2018-09-05 16:24:15 246

原创 STL(三)——list

list介绍STL的list是一个双向链表,插入删除的复杂度为O(1),不像vector,list是有多少元素使用多少空间,不会存在浪费的情况。 list细节:1. list的迭代器不能像vector一样,以普通指针作为迭代器,因为双向链表的迭代器是双向迭代器,不是随机访问迭代器2. 和vector不一样,list的插入、删除等操作不会造成其他迭代器失效(但被操作的迭代器可能失...

2018-09-04 11:26:03 202

原创 STL(二)——vector

vector介绍vector和array相比有以下优点:1. 不用手动指定数组大小,更灵活2. vector有更高效的内存管理策略,更高效 vector一些注意点:1. 使用三个变量标记数组的头部Begin、尾部End和目前可用空间的尾部Memory_End。这三个标记可以简化代码,vector的begin()/end()/size()/capacity()可以很轻...

2018-09-03 16:05:37 92

原创 STL(一)——迭代器

迭代器(iterator)stl的思想是将算法和数据结构分开,而迭代器正是扮演了将他们分开的角色。不管数据结构如何,只要实现了相应的迭代器,就能够使用算法而无需顾及数据内部实现。 迭代器类型试想一下,让你为自己的数据结构设计访问接口,你会怎么设计?比如针对链表,只能单步访问;而针对数组,则可以进行跨步。不同的数据结构有不同的访问限制,由此就引入了不同类型的“接口”。迭代器考虑到了不...

2018-08-31 10:49:40 294

空空如也

空空如也

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

TA关注的人

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