自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(145)
  • 问答 (2)
  • 收藏
  • 关注

原创 longest consecutive sequence

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 consecutive elements sequence is[1, 2, 3, 4].

2016-04-12 23:33:21 413

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

2016-04-10 23:18:20 234

原创 merge k sorted lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.class Solution{ public: ListNode* mergeKLists(vector<ListNode*> &lists) { if (lists.

2016-04-09 23:56:16 351

转载 堆排序

堆排序       堆排序是利用堆的性质进行的一种选择排序。下面先讨论一下堆。1.堆  堆实际上是一棵完全二叉树,其任何一非叶节点满足性质:  Key[i]=Key[2i+1]&&key>=key[2i+2]  即任何一非叶节点的关键字不大于或者不小于其左右孩子节点的关键字。  堆分为大顶堆和小顶堆,满足Key[i]>=Key[2i+1]&&key>

2015-08-27 14:44:56 335

转载 c++ volatile

1. 为什么用volatile?    C/C++ 中的 volatile 关键字和 const 对应,用来修饰变量,通常用于建立语言级别的 memory barrier。这是 BS 在 "The C++ Programming Language" 对 volatile 修饰词的说明:A volatile specifier is a hint to a compiler that

2015-08-24 20:20:22 479

原创 Effective c++读书笔记

条款5:   如果你打算在一个"内含引用成员"的class内支持赋值操作,你必须自己定义拷贝赋值运算符.   只有生出的代码合法且有适当机会证明它有意义.其中一个条件不符合,编译器会拒绝为class生出opetator=(如数据成员为引用类型或者const类型).

2015-08-21 11:49:30 377

转载 java 多态

面向对象编程有三大特性:封装、继承、多态。封装隐藏了类的内部实现机制,可以在不影响使用的情况下改变类的内部结构,同时也保护了数据。对外界而已它的内部细节是隐藏的,暴露给外界的只是它的访问方法。继承是为了重用父类代码。两个类若存在IS-A的关系就可以使用继承。,同时继承也为实现多态做了铺垫。那么什么是多态呢?多态的实现机制又是什么?请看我一一为你揭开:所谓多态就是指程序中定义

2016-12-27 00:09:04 339

转载 深入理解java异常处理机制

1. 引子       try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解。不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单、听话。不信?那你看看下面的代码,“猜猜”它执行后的结果会是什么?不要往后看答案、也不许执行代码看真正答案哦。如果你的答案是正确,那么这篇文章你就不用浪费时间看啦。

2016-11-23 17:35:54 437

转载 从关系型数据库到非关系型数据库

1. 关系型数据库关系型数据库,是指采用了关系模型来组织数据的数据库。关系模型是在1970年由IBM的研究员E.F.Codd博士首先提出的,在之后的几十年中,关系模型的概念得到了充分的发展并逐渐成为主流数据库结构的主流模型。简单来说,关系模型指的就是二维表格模型,而一个关系型数据库就是由二维表及其之间的联系所组成的一个数据组织。关系模型中常用的概念:

2016-11-07 09:31:16 411

转载 一个经典例子让你彻彻底底理解java回调机制

以前不理解什么叫回调,天天听人家说加一个回调方法啥的,心里想我草,什么叫回调方法啊?然后自己就在网上找啊找啊找,找了很多也不是很明白,现在知道了,所谓回调:就是A类中调用B类中的某个方法C,然后B类中反过来调用A类中的方法D,D这个方法就叫回调方法,这样子说你是不是有点晕晕的,其实我刚开始也是这样不理解,看了人家说比较经典的回调方式:Class A实现接口CallBack callback

2016-11-04 13:38:29 370

转载 sql server触发器

INSTEAD OF 触发器用来代替通常的触发动作,即当对表进行INSERT、UPDATE 或 DELETE 操作时,系统不是直接对表执行这些操作,而是把操作内容交给触发器,让触发器检查所进行的操作是否正确。如正确才进行相应的操作。因此,INSTEAD OF 触发器的动作要早于表的约束处理。INSTEAD OF 触发器的操作有点类似于完整性约束。在对数据库的操纵时,有些情况下使用约束可以达到更

2016-10-12 17:30:36 398

转载 深入理解Java虚拟机到底是什么

什么是Java虚拟机作为一个Java程序员,我们每天都在写Java代码,我们写的代码都是在一个叫做Java虚拟机的东西上执行的。但是如果要问什么是虚拟机,恐怕很多人就会模棱两可了。在本文中,我会写下我对虚拟机的理解。因为能力所限,可能有些地方描述的不够欠当。如果你有不同的理解,欢迎交流。我们都知道Java程序必须在虚拟机上运行。那么虚拟机到底是什么呢?先看网上搜索到的比较靠谱的

2016-10-10 14:46:41 403

转载 【手把手教你全文检索】Apache Lucene初探

讲解之前,先来分享一些资料   首先呢,学习任何一门新的亦或是旧的开源技术,百度其中一二是最简单的办法,先了解其中的大概,思想等等。这里就贡献一个讲解很到位的ppt。已经被我转成了PDF,便于搜藏。   其次,关于第一次编程初探,建议还是查看官方资料。百度到的资料,目前Lucene已经更新到4.9版本,这个版本需要1.7以上的JDK,所以如果还用1.6甚至是1.5的

2016-10-08 11:07:33 343

原创 apach poi实现doc转html图片显示问题

图片显示不出来,官方文档说了暂时没提供图片显示功能,需要自己去实现,我在stackoverflow上找到的一段代码,解决了这个问题InlineImageWordToHtmlConverter.javapackage com.gildata.poi;import java.util.Base64;import org.apache.poi.hwpf.converter.WordToHtmlConver

2016-08-12 16:36:07 2916 3

原创 QT连接mysql

之前一直连不上,网上各种方法都试过了,能搜到的都试过了。真的都试过, 也安装了各种版本Mysql, 也重新安装了QT, 都不行。。    最后发现根本不要网上整的那么麻烦。   我用的是QT5,  只要把mysql lib目录下的libmysql.dll 拷贝到qt的bin目录下就可以了。  最关键的是,  libmysql.dll要与qt的位数一样, 比如qt是x86的,mysql也要是x86的

2016-05-14 09:08:45 348

原创 简单的UDP通信的例子

客户端向服务端发送字符串UDP TEST,服务器接收数据后将接收到的字符串发送回客户端udp_server.c#include <sys/types.h>#include <sys/socket.h> /*socket()/bind()*/#include <linux/in.h> /*struct sockaddr_in*/#include <string.h> /*memset

2016-04-24 09:58:27 1165

原创 IO模型

IO的方式有阻塞IO,非阻塞IO,IO复用,信号驱动,异步IO等。 1.阻塞IO 阻塞IO是最通用的IO类型,使用这种模型进行数据接收时,在数据没有到之前程序会一直等待。2.非阻塞IO 当把套接字设置为非阻塞的IO,则对每次请求,内核都不会阻塞,会立即返回; 当没有数据的时候,会返回一个错误。3.IO复用 使用IO复用模型可以在等待的时候加入超时时间,当超时时间没有到达的时候与阻

2016-04-21 16:56:20 293

转载 网络IO模型

同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出的答案都可能不同,比如wiki,就认为asynchronous IO和non-blocking IO是一个东西。这其实是因为不同的人的知识背景不同,并且在讨论这个问题的时候上下文(context)也不

2016-04-21 13:11:57 240

原创 字节序转换函数

由于主机的千差万别,主机的字节序不能做到统一,但是对于网络上传输的变量,它们的值必须有一个统一的表示方法。网络字节序是指多字节变量在网络传输时的表示方法, 网络字节序采用大端字节序的表示方法。 所以小端字节序的系统通过网络传输变量的时候需要进行字节序转换,而大端字节序的变量则不要。Linux系统提供了如下函数进行字节序的转换。#include <arpa/inet.h>uint32_t htonl

2016-04-16 11:18:32 1644

原创 字节序

字节序是由于不同的主处理器和操作系统,对大于一个字节的变量在内存中的存放顺序不同而产生的。 通常有大端字节序和小端字节序两种。例如一个16位的整数,它由两个字节构成,在有的系统上会将高字节放在内存的低地址上,而有的系统则将高字节放在内存的高地址上,所以存在字节序的问题。Little endian:将低序字节存储在起始地址 Big endian:将高序字节存储在起始地址例如变量的值为0xabcd,

2016-04-14 11:22:46 315

原创 简单的socket编程

服务端tcp_server.c:#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <unistd.h>#include <linux/in.h>#define PORT 8888 //端口地址#define BAC

2016-04-13 18:13:44 283

原创 swap nodes in pairs

Given a linked list, swap every two adjacent nodes and return its head. For example, Given1->2->3->4, you should return the list as2->1->4->3. Your algorithm should use only constant space. You may

2016-04-07 23:14:49 285

原创 Makefile入门

Makefile用于多文件工程的编译例如一个简单的工程1.add.h#ifndef _ADD_H#define _ADD_Hextern int add_int(int a,int b);extern float add_float(float a, float b);#endifadd_int.cint add_int(int a, int b){ return

2016-04-02 11:28:47 267

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

2016-04-01 22:06:45 272

原创 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, Given1->2->3->3->4->4->5, return1->2->5. Given1->1->

2016-03-19 15:46:34 342

原创 partition list

题目: 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 the original relative order of the nodes in ea

2016-03-19 10:52:08 300

原创 remove duplicates from sorted list

题目: 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, return1->2->3./** * Definition for singly-

2016-03-18 23:11:37 387

原创 reverse linked list II

题目: 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->NULL. Note: Given m, n satisfy the fo

2016-03-18 16:36:32 268

原创 rotate list

题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given1->2->3->4->5->NULLand k =2, return4->5->1->2->3->NULL.循环右移链表,注意k可能大于链表长度/** * Definition f

2016-03-18 11:13:24 292

原创 merge two sorted lists

题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct Li

2016-03-17 16:36:15 292

原创 linked list cycle

题目:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?快慢指针class Solution{ public: bool hasCycle(ListNode *head)

2016-03-17 10:37:17 247

原创 reorder list

题目: 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 example, Given{1,2,3,4}, reorder it to{1

2016-03-16 10:55:15 241

原创 sort list

题目: Sort a linked list in O(n log n) time using constant space complexity.//merge sort/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListN

2016-03-15 18:59:03 265

原创 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.先找到中间结点作为二叉搜索树根节点,然后递归。/** * Definition for singly-linked list. * struct ListNode {

2016-03-14 16:22:33 325

原创 copy-list-with-random-pointer

题目: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list./** * Definition for singly-lin

2016-03-14 13:56:46 303

原创 leetcode Median of Two Sorted Arrays

class Solution { public: double findMedianSortedArrays(int A[], int m, int B[], int n) { int total = m + n; if (total & 0x1) return find_kth(A, m, B, n, total / 2 + 1); else return (fi

2016-02-06 23:26:15 285

原创 Search in Rotated Sorted Array

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 target value to search. If found in the array return its index

2015-10-26 21:35:17 311

原创 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 first five elemen

2015-10-23 22:01:29 297

原创 static 与 const 的作用总结

一. static1) 全局静态变量作用: 不会被其他文件访问,修改, 其他文件可以使用相同名字的变量, 不会发生冲突, 达到隐藏的作用。2)  局部静态变量作用: 保持变量内容的持久在局部变量前加上关键字static, 局部变量就被定义成一个局部静态变量。当static用来修饰局部变量的时候,它就改变了局部变量的存储位置,从原来的栈中存放改为静态存储区。但是局部静态变量在离开

2015-10-20 20:18:13 360

原创 Implement strStr

mplement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.先来暴力解法: (kmp看懂后再补。。)class Solution { public: int strStr(st

2015-10-16 21:27:12 264

空空如也

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

TA关注的人

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