自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

记录点滴

用代码窥探数字世界 Hello World

  • 博客(104)
  • 收藏
  • 关注

原创 进程间通信机制(IPC-Inter Process Communication)接口简介

1 linux的信号量机制1.1 semget函数semget函数作用是创建一个新信号量,或去的一个已有信号量的键int semget(key_t key, int num_sems, int sem_flags);key:整数值。不相关的进程可以通过它访问同一个信号量。(键信号量标识符)(所有其他信号量函数都是使用由semget函数返回的信号量标识符)num_sems

2017-04-14 19:46:14 436

原创 makefile教程

make命令最常用的三个参数:-k :作用是让make命令在发现错误是仍然执行。可以利用这一选项在一次操作中发现所有未编译成功的源文件-n :让make命令输出将要执行的操作步骤,而不是真正执行这些操作。-f   :告诉make命令将哪个文件作为makefile文件。1.1依赖关系依赖关系定义了最终应用程序的每个文件与源文件之间的关系。 例如有3个源文件和3个头文件,如下:

2017-04-10 23:57:15 740

原创 至今用到的常用vim命令记录

shift + ↑或↓  :翻页h :←l :右j :↑k :↓yy 或 Y :复制整行文本。ctrl+n :(在insert模式下)自动提示。多行注释:ctrl+v进入visual模式,ctrl+d 或 箭头 选中,键入大写字母I后,输入//,最后ESC。取消多行注释:ctrl+v进入visual模式,选中要取消的,按d。ctrl+v J :多行连接成一行

2017-04-10 05:03:37 365

转载 C/C++二维数组名和二级指针

1. 指针1.1 一个指针包含两方面:a) 地址值;b) 所指向的数据类型。1.2 解引用操作符(dereference operator)会根据指针当前的地址值,以及所指向的数据类型,访问一块连续的内存空间(大小由指针所指向的数据类型决定),将这块空间的内容转换成相应的数据类型,并返回左值。有时候,两个指针的值相同,但数据类型不同,解引用取到的值也是不同的,例如,

2017-04-03 01:36:31 409

转载 static作用(修饰函数、局部变量、全局变量)

static作用(修饰函数、局部变量、全局变量)在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条。(1)先来介绍它的第一条也是最重要的一条:隐藏。当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性。为理解这句话,我举例来说明。我们要同时编译两个源文件,一个是a.c,另一个是main.c。下面是a.c的内容char a

2017-04-02 01:45:25 571

转载 c++ static的作用,以及static对象在类和函数中区别

转自:点击static对象如果出现在类中,那么该对象即使从未被使用到,它也会被构造以及析构。而函数中的static对象,如果该函数从未被调用,这个对象也就绝不会诞生,但是在函数每次被调用时检查对象是否需要诞生。下面详细说说static的功能以及它的来龙去脉:static作为编程语言里面一种重要的数据类型,它的地位在面试的过程里也是相当的高。为什么要引入static

2017-01-19 07:49:38 307

原创 unix环境高级编程 程序3-11(fileflags.c)全面解析

源程序:#include "apue.h"#include intmain(int argc, char *argv[]){ int val; if (argc != 2) err_quit("usage: a.out "); if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0) err_sys("fcntl erro

2017-01-18 11:09:00 811

原创 Github Webbench 源码分析+学习(待续)

前言:Webbench 是一个古老而著名的网站压力测试工具,简单而实用。如果你不清楚你的网站能承受多大的压力,或者你想分析对比两个网站的性能,webbench 再好用不过了。Gitbub 地址:https://github.com/cnnewjohn/webbench1,linux编程学习:Makefile记得以前linux程序都是直接g++编译的(好几行是一个命令

2017-01-16 02:10:24 737

原创 57. Insert Interval , STL的使用

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 times.E

2017-01-07 03:45:34 292

原创 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]./** * Definition for an interval. * struct I

2017-01-07 02:00:28 289

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

2017-01-07 01:02:38 270

原创 50. Pow(x, n) 二分应用的又一经典案例

Implement pow(x, n).需要注意的两点1, 当n为 INT_MIN时: int n = INT_MIN; int a = -n; // a == -22147483648 int b = abs(n);// b == -221474836482,n 右移了多少次, x 翻多少翻,而不是ans翻多少翻,因为还有ans = ans * x;AC 代码:

2017-01-06 23:56:41 388

原创 48. Rotate Image 旋转矩阵的通用方法

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {public:/* * clockwise rotate *

2017-01-06 22:42:22 416

原创 42. Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1],

2017-01-06 21:52:03 248

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

2017-01-06 13:18:12 179

原创 38. Count and Say

The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as 

2017-01-06 11:50:56 206

原创 35. Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.

2017-01-06 10:50:20 204

原创 34. Search for a Range 史上最简洁的二分搜索的写法

Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the

2017-01-06 10:22:00 501

原创 33. Search in Rotated Sorted Array 旋转排序数组极值的二分求法

Suppose an array sorted in ascending order 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 target value to search. If foun

2017-01-06 02:56:07 370

原创 31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2017-01-06 01:32:28 365

原创 29. Divide Two Integers 每一行都是精炼

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.法一:可以直观的利用除数的倍数,但如果这个倍数很大(题目中要求不能用乘法)则会造成LTE,此法不可行!!!class Solution {public

2017-01-06 00:25:14 245

原创 27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2017-01-05 21:34:38 182

原创 26. Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with

2017-01-05 20:37:08 171

原创 25. Reverse Nodes in k-Group 怎样不使用额外空间翻转一个单向链表?

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is

2017-01-05 12:20:19 433

原创 21. Merge Two Sorted Lists 一道基础题的两种精炼解法

方法一:递归/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:

2017-01-05 09:53:11 954

原创 20. Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va

2017-01-05 09:15:48 185

原创 19. Remove Nth Node From End of List 一道简单的双指针

Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the

2017-01-05 03:51:18 264

原创 16. 3Sum Closest 又是一道先排序再双指针问题

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2017-01-05 01:21:24 286

原创 15. 3Sum hash解法 vs 双指针解法

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain d

2017-01-05 00:45:30 1153

原创 14. Longest Common Prefix 简单的题,但是有精简代码的小技巧

Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector& strs) { string res; int h = strs.s

2017-01-04 12:03:42 367

原创 12. Integer to Roman 13. Roman to Integer 玩转罗马数字

int -> Romanclass Solution {public: string intToRoman(int num) { char* c[4][10]={ {"","I","II","III","IV","V","VI","VII","VIII","IX"}, {"","X","XX","XXX","XL","

2017-01-04 11:03:03 293

原创 11. Container With Most Water 双指针问题

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

2017-01-04 10:06:34 218

原创 9. Palindrome Number 多种输入情况的考察

Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin

2017-01-04 08:57:09 222

原创 8. String to Integer (atoi) 对于输入情况的考察

以下几种情况要考虑到1,排除输入空格问题2,确定正负3,排除字母4,处理overflowclass Solution {public: int myAtoi(string str) { if (str.empty()) return 0; int i = 0, sign = 1; while (i + 1 < str.size() && isspace(st

2017-01-04 07:47:49 288

原创 7. Reverse Integer 一个简单但是非常考察思维全面性的题目。

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c

2017-01-04 06:48:25 278

原创 6. ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I

2017-01-04 03:14:54 224

原创 5. Longest Palindromic Substring 暴力 800ms -> dp 97ms -> 回归原始 3ms AC

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.

2017-01-03 23:54:38 227

原创 2. Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

2017-01-03 20:45:38 222

原创 23. Merge k Sorted Lists 典型的分治,另,合并两个List的好写法

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne

2017-01-03 10:31:25 276

原创 4. Median of Two Sorted Arrays 典型的二分,分治算法, 另 第k小的O(lgk)解法

There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 =

2017-01-02 21:44:04 414

空空如也

空空如也

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

TA关注的人

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