自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode 83:Remove Duplicates from Sorted List

题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.思路:这题很简单,直接上代码

2015-11-30 21:00:02 273

原创 leetcode 82:Remove Duplicates from Sorted List II

题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi

2015-11-30 20:49:33 290

原创 leetcode 81:Search in Rotated Sorted Array II

题目: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 function to determine if a given target

2015-11-29 20:41:42 345

原创 leetcode 80:Remove Duplicates from Sorted Array II

题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the f

2015-11-29 15:56:25 260

原创 leetcode 79:Word Search(redo)

题目:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or v

2015-11-29 13:20:27 270

原创 leetcode 78:Subsets

题目:Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.

2015-11-27 23:08:28 274

原创 leetcode 77:Combinations

题目: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:[ [2,4], [3,4], [2,3], [1,2], [1,3],

2015-11-27 22:45:32 273

原创 leetcode 76:Minimum Window Substring

题目: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 = "ADOBECODEBANC"T = "ABC"Minimum windo

2015-11-26 22:39:31 301

原创 leetcode 75:Sort Colors

题目: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 red, white and blue.Here, we will use the

2015-11-26 21:38:32 222

原创 leetcode 74:Search a 2D Matrix

题目:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first intege

2015-11-26 20:57:08 350

原创 leetcode 72:Edit Distance

题目:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitt

2015-11-24 20:18:27 216

原创 leetcode 70:Climbing Stairs

题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?思路:这题和前面Unique Path

2015-11-24 19:06:19 228

原创 leetcode 69:

题目:Implement int sqrt(int x).Compute and return the square root of x.思路:用二分法,比较简单时间复杂度:O(lgn)class Solution {public: int sqrt(int x) { if (0 == x) return 0;

2015-11-23 19:29:04 258

原创 list::swap函数

void swap (list& x);Swap contentExchanges the content of the container by the content of x, which is another list of the same type. Sizes may differ.After the call to this member function,

2015-11-20 20:45:55 1596

原创 copy函数

元素复制算法copy。该算法主要用于容器之间元素的拷贝,即将迭代器区间[first,last)的元素复制到由复制目 标result给定的区间[result,result+(last-first))中。下面我们来看看它的函数原型: template OutputIterator copy( InputIterator _First,

2015-11-20 10:24:28 930

原创 leetcode 66:Add Binary

题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".string addBinary(string a, string b) { string result = ""; i

2015-11-19 22:00:57 410

原创 leetcode 65:Plus One

题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.思路:这题比较简单

2015-11-19 21:33:54 266

原创 leetcode 63:Unique Paths II

题目:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively

2015-11-19 20:56:09 251

原创 leetcode 62:Unique Paths

题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to rea

2015-11-19 20:32:10 253

原创 leetcode 61:Rotate List

题目:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.思路:这题可以先确定链表数,然后找到需要截断的结

2015-11-19 19:47:11 236

原创 leetcode 60:Permutation Sequence

题目:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213"

2015-11-18 21:33:23 290

原创 leetcode 59:Spiral Matrix II

题目:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9

2015-11-18 21:15:57 296

原创 leetcode 58:Length of Last Word

题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A

2015-11-18 20:49:43 254

原创 leetcode 57:Insert Interval

题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start ti

2015-11-18 20:31:36 393

原创 leetcode 56:Merge Intervals

题目:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].struct Interval { int start; int end; In

2015-11-18 19:27:35 274

原创 Expression : invalid operator <

今天用sort来对vector进行排序,然后排序函数如下: static bool comp(const Interval a, const Interval b) { return a.start > b.start ? 1 : (a.start < b.start ? -1 : 0); }结果一直提示错误。后来查了下,大概是出这个错是因为VS2005,VS2008后的sor

2015-11-18 19:03:34 315

原创 仿函数与临时对象

仿函数(functor),就是使一个类的使用看上去象一个函数。其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了。所谓临时变量,就是一种无名对象。有的时候可以制造一些临时对象,可以使程序干净清爽。可以制造临时对象的方法是,在类别名称之后直接加一对小括号,并可指定初值,其意义相当于调用相应的constructor且不指定对象名称。STL最常将此技巧应用于仿

2015-11-18 13:11:41 451

原创 template参数设定为默认值

template的参数可以设定为默认值,具体操作如下:#include #include using namespace std;class alloc{};template class deque {public: deque() { cout << "deque" << endl; }};template >class stack {pu

2015-11-18 12:42:18 1408

原创 关于模板类中静态成员

类模板实例化的每个模板类都有自己的类模板静态数据成员,该模板类的所有对象共享一个静态数据成员。比如int的所有实例共享一个静态数据成员,char的所有实例共享一个。下面来看个例子:#include using namespace std;template class testClass{public: static int _data;};int testCla

2015-11-18 12:22:01 1002

原创 leetcode 54:Jump Game

题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.De

2015-11-16 23:00:58 237

原创 leetcode 53:Spiral Matrix

题目:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9

2015-11-16 21:39:14 290

原创 leetcode 52:Maximum Subarray

题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−

2015-11-16 20:59:19 303

原创 leetcode 50:Pow(x, n)

题目:Implement pow(x, n).思路:这题考的是用最短的时间来求幂次方。如果我们用for循环来做,则要做n次乘法,时间复杂度为O(n);如果我们用二分法来做,即先求pow(x,n/2),在将结果相乘,这样只需分lg(n)次,每次做2次或者3次乘法,时间复杂度为O(lgn)。注意边界条件,n可以为负值。实现如下:class Solution {pu

2015-11-16 19:52:15 335

转载 thread poll

转自:http://blog.csdn.net/hinyunsin/article/details/6650879/定义         什么是线程池?简单点说,线程池就是有一堆已经创建好了的线程,初始它们都处于空闲等待状态,当有新的任务需要处理的时候,就从这个池子里面取一个空闲等待的线程来处理该任务,当处理完成了就再次把该线程放回池中,以供后面的任务使用。当池子里的线程全都处理忙

2015-11-15 23:07:04 707

原创 leader-follower model

领导者-跟随者模型如下:有若干个线程(一般组成线程池)用来处理大量的事件有一个线程作为领导者,等待事件的发生;其他的线程作为追随者,仅仅是睡眠。假如有事件需要处理,领导者会从追随者中指定一个新的领导者,自己去处理事件。唤醒的追随者作为新的领导者等待事件的发生。处理事件的线程处理完毕以后,就会成为追随者的一员,直到被唤醒成为领导者。假如需要处理的事件太多,而线程数量不够(能够动态创建线程处理

2015-11-15 21:30:07 866

转载 Classic network server architecture model

前言事件驱动为广大的程序员所熟悉,其最为人津津乐道的是在图形化界面编程中的应用;事实上,在网络编程中事件驱动也被广泛使用,并大规模部署在高连接数高吞吐量的服务器程序中,如 http 服务器程序、ftp 服务器程序等。相比于传统的网络编程方式,事件驱动能够极大的降低资源占用,增大服务接待能力,并提高网络传输效率。关于本文提及的服务器模型,搜索网络可以查阅到很多的实现代码,所以,本文将

2015-11-15 21:18:56 284

原创 chat function based on pthread and ipc

//client.c#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAXLEN 1024/*消息类型*/struct message{

2015-11-14 22:25:48 561 1

原创 用一个消息队列(System V)实现客户端-服务器端

#include#include#include#include#include#define KEY_MSG 0x101#define MSGSIZE 64typedef struct{ long mtype; char mtext[MSGSIZE];}msgbuf;#define LEN sizeof(msgbuf)-sizeof(long)void ma

2015-11-13 13:13:35 595

原创 system V消息队列

#include #include #include #include int main(int argc,char **argv){ int c,oflag,mqid; oflag=IPC_CREAT|0666; //创建,且允许所有进程读写

2015-11-12 23:13:54 326

原创 UDP多播

#include #include #include #include #include #include #include #include #define BUFLEN 255int main(int argc, char **argv){ struct sockaddr_in peeraddr; struct in_addr ia; int sockfd;

2015-11-12 15:23:11 327

空空如也

空空如也

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

TA关注的人

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