自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(56)
  • 资源 (9)
  • 收藏
  • 关注

原创 leetcode——String to Integer (atoi)

一、如果字符串为空,返回0二、去除字符串首部的空格三、判断正负号四、判断并转化数字字符,如果遇到非数字字符,就返回已转化的值五、分别考虑正数和负数的溢出情况class Solution {public: int myAtoi(string str) { if (str.empty()) return 0; int i = 0;

2016-08-31 22:31:45 330

原创 数组最长递增子序列

int longest_increase_seq1(const vector& nums){ vector max_lens(nums.size(), 1);//max_lens[i]表示数组nums[0,...,i]最长递增子序列的长度 for (int i = 0; i < nums.size(); ++i) { int max_len = 0;

2016-08-21 19:50:15 359

原创 最长公共子串和最长公共子序列

求解左边矩阵对角上连续出现的1的个数也就是求解右边矩阵中的最大值int longest_common_substring(const char* str1, const char* str2){ int len1 = strlen(str1), len2 = strlen(str2); int *pd = new int[len1]; memset(pd, 0, le

2016-08-19 23:19:41 391

原创 二叉树递归/非递归遍历

递归遍历//前序遍历void preorder(TreeNode *root, vector &path){ if(root != NULL) { path.push_back(root->val); preorder(root->left, path); preorder(root->right, path); }}

2016-08-09 11:27:01 300

原创 非递归求取二叉树的最大/小深度

分层遍历的思路:二叉树分层遍历用到的是BFS(广度优先搜索),显然这必须维护一个队列。但是一个队列只能得到遍历结果,并不能一层一层分开,所以必须使用两个队列curr和next,curr保存当前层的所有结点指针,next保存下一层的结点指针,遍历的过程就是出队列的过程,在对curr出队列的同时将推出来的结点的非空左右子结点压入队列next,直到为空那么当前层遍历完毕,同时下一层的所有结点指针也保

2016-08-09 11:16:25 1958

转载 守护进程编程惯例

调用fork然后使父进程退出(exit)(1)如果该守护进程是作为shell命令启动,那么父进程终止使得shell认为这条命令执行完毕(2)使得子进程不是进程组组长,保证后续的setsid()系统调用成功调用setsid(),脱离控制终端,登录会话和进程组先介绍一下Linux中的进程与控制终端,登录会话和进程组之间的关系:进程属于一个进程组,进程组号(GID)就是进程组

2016-08-02 11:32:04 397

转载 c++POD 简介

啥是POD类型?POD全称Plain Old Data。通俗的讲,一个类或结构体通过二进制拷贝后还能保持其数据不变,那么它就是一个POD类型。平凡的定义1.有平凡的构造函数2.有平凡的拷贝构造函数3.有平凡的移动构造函数4.有平凡的拷贝赋值运算符5.有平凡的移动赋值运算符6.有平凡的析构函数7.不能包含虚函数8.不能包含虚基类#include

2016-08-01 12:48:24 1378

原创 pthread的互斥量和自旋锁

一、自旋锁与互斥量的区别在多处理器环境中,自旋锁最多只能被一个可执行线程持有。如果一个可执行线程试图获得一个被争用(已经被持有的)自旋锁,那么该线程就会一直进行忙等待,自旋,也就是空转,等待锁重新可用。如果锁未被争用,请求锁的执行线程便立刻得到它,继续执行。一个被争用的自旋锁使得请求它的线程在等待锁重新可用时自旋,特别的浪费CPU时间,所以自旋锁不应该被长时间的持有。实际上,这就是自旋锁的设计

2016-07-29 20:53:32 4064

转载 c++重载、覆盖、隐藏

重载(overload)是指函数不同的参数列表,对同名函数的名称做修饰,然后这些同名函数就成了不同的函数。在同一可访问域内(注意同一访问域,基类和派生类不属于同一访问域)被声明的几个具有不同参数列表(参数类型、个数、顺序)的同名函数,程序会根据不同的参数列来确定具体调用哪个函数。对于重载函数的调用,在编译期间就已经确定,是静态的,它们的地址在编译期间就绑定好了,与多态无关。注意,重载不关心函数的返

2016-07-27 21:20:47 289

转载 指针大小由什么决定

首先,介绍几个基本概念:(主要摘自百度百科)字长:在同一时间中处理二进制数的位数叫字长(CPU处理能力)。通常称处理字长为8位数据的CPU叫8位CPU,32位CPU就是在同一时间内处理字长为32位的二进制数据。二进制的每一个0或1是组成二进制的最小单位,称为一个比特(bit)。   一般说来,计算机在同一时间内处理的一组二进制数称为一个计算机的“字”,而这组二进制数的位数就是“字长

2016-07-27 21:14:36 664

转载 Linux进程状态解析之R、S、D、T、Z、X

Linux是一个多用户,多任务的系统,可以同时运行多个用户的多个程序,就必然会产生很多的进程,而每个进程会有不同的状态。众所周知,现在的分时操作系统能够在一个CPU上运行多个程序,让这些程序表面上看起来是在同时运行的。linux就是这样的一个操作系统。在linux系统中,每个被运行的程序实例对应一个或多个进程。linux内核需要对这些进程进行管理,以使它们在系统中“同时”运行。li

2016-07-25 17:21:12 2904

原创 Linux时间系统调用总结

#include typedef __time_t time_t;//获取time_t表示的当前时间time_t time(time_t *t);struct timeval{ __time_t tv_sec;//秒 __suseconds_t tv_usec;//微秒};//获取timeval表示的当前时间,有BUG,少用int gettimeofday(st

2016-07-20 11:05:54 1487

原创 leetcode——Intersection of Two Arrays II

题目:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].class Solution {public: vector intersect(vect

2016-07-15 20:08:02 400

转载 一个sample学会使用epoll

#include #include #include #include #include #include #include #include #include #include #include #include #define MAX_EVENT_NUMBER 1024#define TCP_BUFFER_SIZE 512#define UDP_BUFFER_

2016-07-15 10:36:51 341

原创 一个sample学会使用c++比较函数对象和hash函数对象

/*1、自定义hash函数对象用于unordered_set中2、自定义Compare函数对象用于排序3、学习使用优先级队列priority_queue*/#include #include #include #include #include using namespace std;//已知0 <= x, y < 100class point{public:

2016-07-13 23:27:14 1078

原创 epoll系列系统调用

一、文件描述符就绪epoll用来同时监听多个文件描述符是否就绪,那么哪些情况下文件描述符可以被认为是可读、可写或者异常呢?1、文件描述符可读的情况socket内核接收缓冲区中的字节数大于或等于其低水位标记SO_RCVLOWAT。此时我们可以无阻塞地读,并且读操作返回的字节数大于0.socket通信的对方关闭连接。此时对该socket的读操作将返回0.监听socket上有新的连接

2016-07-13 17:05:42 581

原创 leetcode——Isomorphic Strings

题目:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced wi

2016-07-10 21:54:32 283

原创 leetcode——Count Primes

题目:输出小于n的质数的个数方法一:能不能快速判断一个数字n是不是质数呢?1、遍历所有小于n的整数,如果都不可以整除那么n为质数2、遍历所有小于sqrt(n)的整数,如果都不可以整除那么n为质数3、遍历所有小于sqrt(n)的质数,如果都不可以整除那么n为质数显然3是最快的做法,因此我们在搜索到一个质数后要将其保存到数组后面,下次直接遍历质数数组来判断n是不是质数c

2016-07-10 19:53:08 305

原创 java实现的线程池

线程池(Thread Pool)对于限制应用程序中同一时刻运行的线程数很有用。因为每启动一个新线程都会有相应的性能开销,每个线程都需要给栈分配一些内存等等。        我们可以把并发执行的任务传递给一个线程池,来替代为每个并发执行的任务都启动一个新的线程。只要池里有空闲的线程,任务就会分配给一个线程执行。在线程池的内部,任务被插入一个阻塞队列(Blocking Queue ),线程池里的线

2016-07-08 15:57:22 296

原创 leetcode——Single Number III

题目一:Given an array of integers, every element appearstwice except for one. Find that single one.class Solution {public: int singleNumber(vector& nums) { int res = 0; for (au

2016-07-07 19:43:14 233

原创 java实现的读写锁

一、读写锁简介        如果对于资源的读操作次数远大于写操作次数那么使用读写锁可以提高性能,否则不仅增加了系统复杂性且没有性能优势。        可读的前提是资源没有被写占有;        可写的前提是资源没有被读占有且没有被写占有二、读写权限和优先级1、什么条件下线程肯定有资格获取读权限        (1)该线程已经获得写权限        (2)该线

2016-07-07 11:39:58 575

原创 leetcode——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 window is "

2016-07-06 21:17:13 307

转载 深入JVM锁机制

这是两篇关于JAVA锁机制原理的文章:http://developer.51cto.com/art/201111/304378.htmhttp://developer.51cto.com/art/201111/304378.htm

2016-07-06 14:40:16 302

原创 leetcode——Longest Substring Without Repeating Characters

题目:Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is

2016-07-05 15:35:33 211

原创 Java实现的公平锁

参考文献:http://tutorials.jenkov.com/java-concurrency/starvation-and-fairness.html使用公平锁的原因是为了防止饥饿,导致饥饿的原因如下: 1、高优先级线程吞噬所有的低优先级线程的CPU时间(高优先级任务会获取更多的时间片)。2、线程被永久堵塞在一个等待进入同步块的状态,因为其他线程总是能在它之前持续地对该同

2016-07-05 11:45:14 1416

原创 leetcode——Find the Duplicate Number

题目:Given an array nums containing n + 1 integers where each integer is between 1 andn (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate nu

2016-07-04 20:53:59 308

原创 leetcode——Majority Element II

题目:Given an integer array of size n, find all elements that appear more than⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.分析:        针对“选择出现次数大于n/2的元素”的问题,每次舍弃两个不同的元

2016-07-04 17:20:31 292

转载 Linux调度器内幕

原文链接:http://www.ibm.com/developerworks/cn/linux/l-scheduler/本文将回顾一下 Linux 2.6 的任务调度器及其最重要的一些属性。在深入介绍调度器的详细信息之前,让我们先来理解一下调度器的基本目标。什么是调度器?通常来说,操作系统是应用程序和可用资源之间的媒介。典型的资源有内存和物理设备。但是 CPU 也可以认为是一个资源

2016-06-30 22:44:18 438

原创 leetcode——Minimum Size Subarray Sum

题目:Given an array of n positive integers and a positive integers, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the arra

2016-06-30 13:14:10 207

原创 leetcode——Find Minimum in Rotated Sorted Array II

题目一: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).Find the minimum element.You may assume no duplicate exists i

2016-06-30 10:58:44 258

原创 leetcode——Find Peak Element

题目:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks,

2016-06-30 10:47:00 303

原创 leetcode——Maximum Product Subarray

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

2016-06-28 21:22:17 301

原创 二叉树的最大路径和与最远结点距离

首先确定一下单路径的定义:某个结点的单路径就是只经过该结点且不同时包含其左右子树上的结点的路径一、求连接二叉树的任意两个结点的路径的最大和分析:对于二叉树上的每一个结点,求出经过它的路径的最大和,并更新这个最大和即可。经过它的最大和路径可能有三种情况:1、其左子结点的最大单路径和大于0,且其右子结点的最大单路径和大于0,那么经过该结点的最大和路径通过该结点跨过左右子树2、其左子

2016-06-25 20:58:19 4337

原创 leetcode——Maximal Rectangle

题目: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 histogram.Above is a histogram where widt

2016-06-22 11:15:21 472 2

原创 leetcode——Word Search

题目: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 verti

2016-06-21 15:02:45 378 1

原创 leetcode——Spiral Matrix

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

2016-06-21 13:58:54 334

原创 leetcode——First Missing Positive

题目:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses const

2016-06-21 11:50:21 192

原创 leetcode——Merge Intervals

区间合并问题

2016-06-19 14:32:58 204

原创 leetcode——Jump Game II

贪心和动态规划

2016-06-18 15:27:10 308

原创 leetcode——Combination Sum

子集问题的应用

2016-06-17 23:05:02 215

introduction for c shell programing

c shell 编程的经典全面国外教程,讲解简单易懂,适合初学者看同时也可作为开发者的参考书。。

2011-12-28

电子钟单片机源码

单片机c语言的电子钟源码,包括随时设定时间、闹钟、秒表等多项功能。。。

2011-12-28

算法导论全英文答案

算法导论是一本非常经典的教材,看完教材的正文部分是不是还要试试课后习题加深认识举一反三? 试试这份参考资料吧

2011-12-28

深入理解计算机系统

高清图书,国外经典教程,程序员必备图书。本书适合那些想要写出更快更可靠程序的程序员阅读。。

2011-12-24

gcc命令大全

linux gcc编程初学者的指南,书中全面包含各种gcc命令。。。

2011-12-09

计算机操作系统教程

985高校的计算机操作系统教程,知识点全面,讲解严密通俗易懂。。。

2011-12-03

SFM(三维重建技术)

三维重建,将不同视角的多张图片处理成物体三维信息的方法,简明易懂。。。

2011-12-03

c51 单片机编程

最简单易懂的教程,抛开繁杂的单片机工作原理,用最通俗的语言让读者真正学懂单片机

2011-11-16

空空如也

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

TA关注的人

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