06 2017 档案
摘要:题目描述 Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order
阅读全文
摘要:题目描述 Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S ="ADOB
阅读全文
摘要:C++ 智能指针详解 一、简介 由于 C++ 语言没有自动内存回收机制,程序员每次 new 出来的内存都要手动 delete。程序员忘记 delete,流程太复杂,最终导致没有 delete,异常导致程序过早退出,没有执行 delete 的情况并不罕见。 用智能指针便可以有效缓解这类问题,本文主要讲
阅读全文
摘要:四、类模板的默认模板类型形参 1、可以为类模板的类型形参提供默认值,但不能为函数模板的类型形参提供默认值。函数模板和类模板都可以为模板的非类型形参提供默认值。 2、类模板的类型形参默认值形式为:template<class T1, class T2=int> class A{};为第二个模板类型形参
阅读全文
摘要:C++模板 模板是C++支持参数化多态的工具,使用模板可以使用户为类或者函数声明一种一般模式,使得类中的某些数据成员或者成员函数的参数、返回值取得任意类型。 模板是一种对类型进行参数化的工具; 通常有两种形式:函数模板和类模板; 函数模板针对仅参数类型不同的函数; 类模板针对仅数据成员和成员函数类型
阅读全文
摘要:1、为什么要引入友元函数:在实现类之间数据共享时,减少系统开销,提高效率 具体来说:为了使其他类的成员函数直接访问该类的私有变量 即:允许外面的类或函数去访问类的私有变量和保护变量,从而使两个类共享同一函数 优点:能够提高效率,表达简单、清晰 缺点:友元函数破环了封装机制,尽量不使用成员函数,除非不
阅读全文
摘要:unordered_map和map类似,都是存储的key-value的值,可以通过key快速索引到value。不同的是unordered_map不会根据key的大小进行排序, 存储时是根据key的hash值判断元素是否相同,即unordered_map内部元素是无序的,而map中的元素是按照二叉搜索
阅读全文
摘要:长连接:指在一个TCP连接上可以连续发送多个数据包,在TCP连接保持期间,如果没有数据包发送,需要双方发检测包以维持此连接,一般需要自己做在线维持。 长连接:指在一个TCP连接上可以连续发送多个数据包,在TCP连接保持期间,如果没有数据包发送,需要双方发检测包以维持此连接,一般需要自己做在线维持。
阅读全文
摘要:尽管内核模块不象应用程序一样顺序执行, 内核做的大部分动作是代表一个特定进程的. 内核代码可以引用当前进程, 通过存取全局项 current, 它在 <asm/current.h> 中定义, 它产生一个指针指向结构 task_struct, 在 <Linux/sched.h> 定义. current
阅读全文
摘要:同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的。所以先限定一下本文的上下文。 一 概念说明 在进行解释之前,首先要说明几个概念:- 用户空间和内核空间- 进程切换- 进程的阻塞- 文件描述符- 缓存 I/O 用户空间与内核空间 现在操作
阅读全文
摘要:epoll - I/O event notification facility在linux的网络编程中,很长的时间都在使用select来做事件触发。在linux新的内核中,有了一种替换它的机制,就是epoll。相比于select,epoll最大的好处在于它不会随着监听fd数目的增长而降低效率。因为在
阅读全文
摘要:select,poll,epoll都是IO多路复用的机制。I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作。但select,poll,epoll本质上都是同步I/O,因为他们都需要在读写事件就绪后自己负责进行读写,也就是说
阅读全文
摘要:git merge是用来合并两个分支的。 git merge b git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 他们的 原理 如下: 假设你现在基于远程分支"origin",创建一个叫"mywork"的分支。 $ git check
阅读全文
摘要:Linux如何查看端口 1、lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:8000 可以看到8000端口已经被轻量级文件系统转发服务lwfs占用 2、netstat -tunlp |grep 端口号,用于查看指定的端口号的进程情况,如查看8000端
阅读全文
摘要:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example,If n = 4 and k = 2, a solution is: 要求 给定两个整数(n,k
阅读全文
摘要:C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static。前者应用于普通变量和函数,不涉及类;后者主要说明static在类中的作用。 1.面向过程设计中的static1.1静态全局变量在全局变量前,加上关键字static,该变量就被定义成为一个静态全局变量。
阅读全文
摘要:一个典型的单例模式构建对象的双重检查锁如下: 1 static Singleton * getSingleObject() 2 { 3 if(singleObject==NULL) 4 { 5 lock(); 6 if(singleObject==NULL) 7 { 8 singleObject =
阅读全文
摘要:单例模式也称为单件模式、单子模式,可能是使用最广泛的设计模式。其意图是保证一个类仅有一个实例,并提供一个访问它的全局访问点,该实例被所有程序模块共享。有很多地方需要这样的功能模块,如系统的日志输出,GUI应用必须是单鼠标,MODEM的联接需要一条且只需要一条电话线,操作系统只能有一个窗口管理器,一台
阅读全文
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array A =[1,1,1,2,2,3], Your function should
阅读全文
摘要:Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a functio
阅读全文
摘要:【题目】 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 targ
阅读全文
摘要:I、Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given1->1->2, return1->2.Given1->1->2->3->3,
阅读全文
摘要:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist
阅读全文
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. PS:将其化解为柱状图求最大体积的问题。先用动态规划的思路,将矩
阅读全文
摘要:【题目】 Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve
阅读全文
摘要:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representati
阅读全文
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements
阅读全文
摘要:The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total num
阅读全文
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, determine t
阅读全文
摘要:一、操作系统引论 操作系统目标 1:方面性,2:有效性,3:可扩展性,4:开放性 操作系统基本特性 1:并发、2:共享、3:虚拟、4:异步 描述多道批处理、分时、实时操作系统的特点各是什么? 批处理操作系统:多道性、无序性、调度性,系统利用率高、吞吐量大、平均周转时间长、但无交互能力。 描述多道批处
阅读全文
摘要:进程间通信(IPC,InterProcess Communication)是指在不同进程之间传播或交换信息。 IPC的方式通常有管道(包括无名管道和命名管道)、消息队列、信号量、共享存储、Socket、Streams等。其中 Socket和Streams支持不同主机上的两个进程IPC。 以Linux
阅读全文
摘要:问题 Ubuntu下有时候插入U盘,发现不能修改其中的内容。例如不能新建文件和文件夹,不能向U盘中复制文件等,系统提示:只读文件系统。原因大概是U盘的文件系统信息出错(保存在一个硬盘或U盘最前面的头,其中有所有文件的信息)。格式化U盘自然可以解决问题,不过会删除U盘上的所有数据。修复U盘而不删除文件
阅读全文
摘要:I Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must
阅读全文
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given1->2->3->4->5->NULL, m = 2 and n = 4, return1->4->3->2->5
阅读全文
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return ["2
阅读全文
摘要:Given a binary tree, return the inordertraversal of its nodes' values. For example:Given binary tree{1,#,2,3}, return[1,3,2].
阅读全文
摘要:Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST'
阅读全文
摘要:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbcac", ret
阅读全文
摘要:【题目】 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains
阅读全文
摘要:自:http://www.zhihu.com/question/23895384 说到Coroutine,我们必须提到两个更远的东西。在操作系统(os)级别,有进程(process)和线程(thread)两个(仅从我们常见的讲)实际的“东西”(不说概念是因为这两个家伙的确不仅仅是概念,而是实际存在的
阅读全文
摘要:优先队列是一种用来维护一组元素构成的结合S的数据结构,其中每个元素都有一个关键字key,元素之间的比较都是通过key来比较的。优先队列包括最大优先队列和最小优先队列,优先队列的应用比较广泛,比如作业系统中的调度程序,当一个作业完成后,需要在所有等待调度的作业中选择一个优先级最高的作业来执行,并且也可
阅读全文
摘要:理解Hash 哈希表(hash table)是从一个集合A到另一个集合B的映射(mapping)。 映射是一种对应关系,而且集合A的某个元素只能对应集合B中的一个元素。但反过来,集合B中的一个元素可能对应多个集合A中的元素。如果B中的元素只能对应A中的一个元素,这样的映射被称为一一映射。这样的对应关
阅读全文
摘要:来源:http://blog.csdn.net/turne/article/details/50488378 看数据结构书的时候碰上的内容,我自己将它化成关于级数的题,然后自己算的过程,基本就是等比级数和等差级数的混合内容。 满二叉树来分析折半查找的平均长度 h=层高 n=节点数 看数据结构书的时候
阅读全文
摘要:内存分配方式 简介 在C++中,内存分成5个区,他们分别是堆、栈、自由存储区、全局/静态存储区和常量存储区。 栈:在执行函数时,函数内局部变量的存储单元都可以在栈上创建,函数执行结束时这些存储单元自动被释放。栈内存分配运算内置于处理器的指令集中,效率很高,但是分配的内存容量有限。 堆:就是那些由 n
阅读全文
摘要:作用域规则告诉我们一个变量的有效范围,它在哪儿创建,在哪儿销毁(也就是说超出了作用域)。变量的有效作用域从它的定义点开始,到和定义变量之前最邻近的开括号配对的第一个闭括号。也就是说,作用域由变量所在的最近一对括号确定。 (1) 全局变量: 全局变量是在所有函数体的外部定义的,程序的所在部分(甚至其它
阅读全文
摘要:rename命令用字符串替换的方式批量改变文件名。 语法 rename(参数) 参数 原字符串:将文件名需要替换的字符串; 目标字符串:将文件名中含有的原字符替换成目标字符串; 文件:指定要改变文件名的文件列表。 实例 将main1.c重命名为main.c rename main1.c main.c
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is
阅读全文
摘要:Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical a
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: But the fol
阅读全文
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and
阅读全文
摘要:Given a binary 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 l
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.
阅读全文
摘要:题意:根据二叉树的中序遍历和后序遍历恢复二叉树。 解题思路:看到树首先想到要用递归来解题。以这道题为例:如果一颗二叉树为{1,2,3,4,5,6,7},则中序遍历为{4,2,5,1,6,3,7},后序遍历为{4,5,2,6,7,3,1},我们可以反推回去。由于后序遍历的最后一个节点就是树的根。也就是
阅读全文
摘要:总结:1、按1继承顺序先排布基于每个父类结构。2、该结构包括:基于该父类的虚表、该父类的虚基类表、父类的父类的成员变量、父类的成员变量。3、多重继承且连续继承时,虚函数表按继承顺序排布函数与虚函数。4、而后排布子类的成员变量。5、排布虚基类的虚函数表。6、虚基类的成员变量 #类中的元素 0. 成员变
阅读全文
摘要:公有继承(public)、私有继承(private)、保护继承(protected)是常用的三种继承方式。 1. 公有继承(public) 公有继承的特点是基类的公有成员和保护成员作为派生类的成员时,它们都保持原有的状态,而基类的私有成员仍然是私有的,不能被这个派生类的子类所访问。 2. 私有继承(
阅读全文
摘要:http://blog.csdn.net/wangxingbao4227/article/details/6772579 C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同的拷贝造成数据不一致问题,将共同基类设置为虚基类。这时从不同的路径继承过来的同名数据成员在内存中就只
阅读全文
摘要:一个空类class A{};的大小为什么是1,因为如果不是1,当定义这个类的对象数组时候A objects[5]; objects[0]和objects[1]就在同一个地址处,就无法区分。 单继承 1 #include<iostream> 2 using namespace std; 3 class
阅读全文
摘要:struct为空时,大小为1. 1、 sizeof应用在结构上的情况 请看下面的结构: 对结构MyStruct采用sizeof会出现什么结果呢?sizeof(MyStruct)为多少呢?也许你会这样求:sizeof(MyStruct)=sizeof(double) sizeof(char) size
阅读全文
摘要:转自:http://blog.csdn.net/haoel 前言 C++中的虚函数的作用主要是实现了多态的机制。关于多态,简而言之就是用父类型别的指针指向其子类的实例,然后通过父类的指针调用实际子类的成员函数。这种技术可以让父类的指针有“多种形态”,这是一种泛型技术。所谓泛型技术,说白了就是试图使用
阅读全文
摘要:I Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree{
阅读全文
摘要:Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST
阅读全文
摘要:一、一个由C/C++编译到程序占用的内存分为以下几个部分: 1、栈区(stack)——由编译器自动分配释放,在不需要的时候自动清除。用于存放函数的参数、局部变量等。操作方式类似数据结构中的栈(后进先出)。 2、堆区(heap)——一般由程序员分配释放,若程序员分配后不释放,程序结束后可能由OS回收。
阅读全文
摘要:参考一: 有关C/C++指针的经典面试题 有关C/C++指针的经典面试题 0.预备知识,最基础的指针 其实最基础的指针也就应该如下面代码: int a; int* p=&a; 也就是说,声明了一个int变量a,然后声明一个int 的指针,*p指向a的地址,&也就是取地址符号,而*是指针中取内容的符号
阅读全文
摘要:有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位。例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可。为了节省存储空间,并使处理简便,C语言又提供了一种数据结构,称为“位域”或“位段”。所谓“位域”是把一个字节中的二进位划分为几个不同的区域, 并说明每个区域的
阅读全文
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the dept
阅读全文
摘要:I、Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
阅读全文
摘要:数组指针(也称行指针)定义 int (*p)[n];()优先级高,首先说明p是一个指针,指向一个整型的一维数组,这个一维数组的长度是n,也可以说是p的步长。也就是说执行p+1时,p要跨过n个整型数据的长度。 如要将二维数组赋给一指针,应这样赋值:int a[3][4];int (*p)[4]; //
阅读全文
摘要:Given a string S and a string T, count the number of distinct subsequences ofT inS. A subsequence of a string is a new string which is formed from the
阅读全文
摘要:1、 Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to N
阅读全文
摘要:1、Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]
阅读全文
摘要: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 fo
阅读全文
摘要:1、 Say you have an array for which the i th element is the price of a given stock on day i . If you were only permitted to complete at most one transa
阅读全文
摘要:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example:Given the below binary tree, Return 6.
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Pan
阅读全文
摘要:Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that: For example, Given:start
阅读全文
摘要:Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: For e
阅读全文
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given[100, 4, 200, 1, 3, 2],The longest
阅读全文
摘要:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number. An example is the root-to-leaf path1->2->3which re
阅读全文
摘要:前面三讲《C++11 并发指南二(std::thread 详解)》,《C++11 并发指南三(std::mutex 详解)》分别介绍了 std::thread,std::mutex,std::future 等相关内容,相信读者对 C++11 中的多线程编程有了一个最基本的认识,本文将介绍 C++11
阅读全文
摘要:上一讲《C++11 并发指南四(<future> 详解二 std::packaged_task 介绍)》主要介绍了 <future> 头文件中的 std::packaged_task 类,本文主要介绍 std::future,std::shared_future 以及 std::future_err
阅读全文
摘要:前面两讲《C++11 并发指南二(std::thread 详解)》,《C++11 并发指南三(std::mutex 详解)》分别介绍了 std::thread 和 std::mutex,相信读者对 C++11 中的多线程编程有了一个最基本的认识,本文将介绍 C++11 标准中 <future> 头文
阅读全文
摘要:转自:http://www.cnblogs.com/haippy/p/3237213.html 上一篇《C++11 并发指南二(std::thread 详解)》中主要讲到了 std::thread 的一些用法,并给出了两个小例子,本文将介绍 std::mutex 的用法。 Mutex 又称互斥量,C
阅读全文
摘要:上一篇博客《C++11 并发指南一(C++11 多线程初探)》中只是提到了 std::thread 的基本用法,并给出了一个最简单的例子,本文将稍微详细地介绍 std::thread 的用法。 std::thread 在 <thread> 头文件中声明,因此使用 std::thread 时需要包含
阅读全文
摘要:在Java 中定义了关键字final,被final修饰的类不能被继承。 首先想到的是在C++中,子类的构造函数会自动调用父类的构造函数。同样,子类的析构函数也会自动调用父类的析构函数。要想一个类不能被继承,只要把它的构造函数和析构函数都定义为私有函数。那么当一个类试图从它那继承的时候,必然会由于试图
阅读全文
摘要:本系列文章主要介绍 C++11 并发编程,计划分为 9 章介绍 C++11 的并发和多线程编程,分别如下: C++11 并发指南一(C++11 多线程初探)(本章计划 1-2 篇,已完成 1 篇) C++11 并发指南二(std::thread 详解)(本章计划 1-2 篇,已完成 1 篇) C++
阅读全文
摘要:引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧,和大家共勉。 相信 Linux 程序员都用过 Pthread, 但有了 C++11 的 std::t
阅读全文
摘要:生产者消费者问题是多线程并发中一个非常经典的问题,相信学过操作系统课程的同学都清楚这个问题的根源。本文将就四种情况分析并介绍生产者和消费者问题,它们分别是:单生产者-单消费者模型,单生产者-多消费者模型,多生产者-单消费者模型,多生产者-多消费者模型,我会给出四种情况下的 C++11 并发解决方案,
阅读全文
摘要:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded
阅读全文
摘要:所谓的原子操作,取的就是“原子是最小的、不可分割的最小个体”的意义,它表示在多个线程访问同一个全局资源的时候,能够确保所有其他的线程都不在同一时间内访问相同的资源。也就是他确保了在同一时刻只有唯一的线程对这个资源进行访问。这有点类似互斥对象对共享资源的访问的保护,但是原子操作更加接近底层,因而效率更
阅读全文
摘要:一. 引子 最近想自己写个简单的 WEB SERVER ,为了先练练手,熟悉下在LINUX系统使用基本的进程、线程、互斥等,就拿以前学过的 OS 问题开开刀啦。记得当年学读者写者问题,尤其是写者优先的时候,那是真心纠结啊。刚才还觉得理解了,过一会儿又糊涂了。现在重新再看,还是容易纠结。没办法,用得少
阅读全文
摘要:一.概念性问答题 第一题:线程的基本概念、线程的基本状态及状态之间的关系? 线程:一个线程是进程的一个顺序执行流。同类的多个线程共享一块内存空间和一组系统资源,线程本身有一个供程序执行时的堆栈。线程在切换时负荷小,因此,线程也被称为轻负荷进程。一个进程中可以包含多个线程。 并发原理 多个线程或进程”
阅读全文
摘要:1. 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者。传统的Unix也支持线程的概念,但是在一个进程(process)中只允许有一个线程,这样多线程就意味着多进程。现在,多线程技术已经被许多操作系统所支持,包括Wi
阅读全文
摘要:I: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For exa
阅读全文
摘要:Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes
阅读全文
摘要:贪心算法的定义:贪心算法是指在对问题求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,只做出在某种意义上的局部最优解。贪心算法不是对所有问题都能得到整体最优解,关键是贪心策略的选择,选择的贪心策略必须具备无后效性,即某个状态以前的过程不会影响以后的状态,只与当前状态有关。解题
阅读全文
摘要:Gas Station There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank
阅读全文
摘要:There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following re
阅读全文
摘要:HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议。 HTTP是一个基于TCP/IP通信协议来传递数据(HTML 文件, 图片文件, 查询结果等)
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up:Can you solve it without using extra space? 快
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 若在while开始时判断fast==slow,会出现误判,即第一次循环时fast
阅读全文
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For
阅读全文
摘要:上面分析了 根据这张图 推倒出 数学公式。 刚接触 不能一下弄明白。下面结合上面文章的分析。仔细推倒一下 , 一般设置 快指针 速度是 慢指针的2倍。及 快指针每次遍历两个指针, 慢指针每次遍历1个指针。 假设上图 快慢指针 在E点相遇,那 相遇点离循环节点D 之间距离是X. 头结点A 离循环节点D
阅读全文
摘要:Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree{1,#,2,3}, return[1,2,3]. Note: Recursive soluti
阅读全文
摘要:Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree{1,#,2,3}, return[3,2,1]. Note: Recursive solut
阅读全文
摘要:Sort a linked list using insertion sort. PS:需要考虑left为head且只有一个数时,此时left->==NULL,若right<left则应更新left。 比较p->next->val与right->val以此来避免需要记录preNode
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. 链表,快慢指针找中点,归并排序。 注意判断条件fast->next!=NULL&&fast->next->next!=NULL,若为fast!=NULL&&f
阅读全文
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 找出二维平面上处于同一条直线上的最大点数 PS: map用法。for(auto pair:slope
阅读全文
摘要:Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*,/. Each operand may be an integer or another expre
阅读全文
摘要:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le
阅读全文
摘要:转自:http://blog.csdn.net/ns_code/article/details/12977901 二叉树是一种非常重要的数据结构,很多其他数据机构都是基于二叉树的基础演变过来的。二叉树有前、中、后三种遍历方式,因为树的本身就是用递归定义的,因此采用递归的方法实现三种遍历,不仅代码简洁
阅读全文
摘要:转自:http://www.cnblogs.com/scnuyz/p/5808808.html bs是浏览器(browser)和服务器(server) cs是静态客户端程序(client)和服务器(server) 区别在于,虽然同样是通过一个程序连接到服务器进行网络通讯,但是bs结构的,客户端运行在
阅读全文
摘要:Linux的SOCKET编程详解 1. 网络中进程之间如何通信 进 程通信的概念最初来源于单机系统。由于每个进程都在自己的地址范围内运行,为保证两个相互通信的进 程之间既互不干扰又协调一致工作,操作系统为进程通信提供了相应设施,如 UNIX BSD有:管道(pipe)、命名管道(named pipe
阅读全文
摘要:本文转自http://blog.csdn.net/wingofeagle/article/details/13020373 深度遍历: 从图中某个顶点v出发,访问此顶点,然后从v的未被访问的邻接点出发深度优先遍历图,直至图中所有和v有路径相通的顶点都被访问到。 其更适合:目标比较明确,以找到目标为主
阅读全文
摘要:一、 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. F
阅读全文
摘要:C++简单实现对象引用计数示例 运行结果如下: ss.value->refCount=1s1.value->refCount=2ss.value->refCount=2s2.value->refCount=1operator =[delete value] value->refCount=0s2.v
阅读全文
摘要:1、TCP/IP的介绍 互联网协议族(Internet Protocol Suite,缩写IPS)是一个网络通信模型,以及一整个网络传输协议家族, 为互联网的基础通信架构。它常被通称为TCP/IP协议族(TCP/IP Protocol Suite,或TCP/IP Protocols), 简称TCP/
阅读全文
摘要:OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 。 完成中继功能的节点通常称为中继系统。在OSI七层模型中,处于不同层的中继系统具有不同的名称。 一个设备工作在哪一层,关键看它工作时利用哪一层的数据头部信息。网桥
阅读全文
摘要:转自:http://blog.csdn.net/liweisnake/article/details/12966761 今天看到一篇文章,是关于java中如何等待所有线程都执行结束,文章总结得很好,原文如下http://software.intel.com/zh-cn/blogs/2013/10/1
阅读全文
摘要:join()是Thread类的一个方法。根据jdk文档的定义: public final void join()throws InterruptedException: Waits for this thread to die. join()方法的作用,是等待这个线程结束;但显然,这样的定义并不清晰
阅读全文
摘要:一、ExecutorService介绍 ExecutorService是Java中对线程池定义的一个接口,它java.util.concurrent包中,在这个接口中定义了和后台任务执行相关的方法: Java API对ExecutorService接口的实现有两个,所以这两个即是Java线程池具体实
阅读全文
摘要:结论:1、不管有木有出现异常,finally块中代码都会执行;2、当try和catch中有return时,finally仍然会执行;3、finally是在return后面的表达式运算后执行的(此时并没有返回运算后的值,而是先把要返回的值保存起来,管finally中的代码怎么样,返回的值都不会改变,任
阅读全文