自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Tim's Blog

The path to your glorious future begins with the steps you take today.

  • 博客(39)
  • 资源 (15)
  • 收藏
  • 关注

原创 [LeetCode]Word Break

Question: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.For example, givens = "leetcode",

2014-04-28 18:26:42 736

原创 [LeetCode]Linked List Cycle

Question:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Answer

2014-04-28 01:05:34 727

原创 [LeetCode]Linked List Cycle II

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

2014-04-28 00:49:19 652

转载 [LeetCode]Max Points on a Line

Question:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析:任意一条直线都可以表述为y = ax + b假设,有两个点(x1,y1), (x2,y2),如果他们都在这条直线上则有

2014-04-27 02:58:28 529

原创 [LeetCode]Evaluate Reverse Polish Notation

Question:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples:

2014-04-27 01:56:11 599

原创 [LeetCode]Reverse Words in a String

Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes

2014-04-26 23:17:41 516

原创 虚函数和类的多态性

多态特性让程序员省去了细节的考虑,提高了开发效率,使代码大大的简化,当然虚函数的定义也是有缺陷的,因为多态特性增加了一些数据存储和执行指令的开销,所以能不用多态最好不用。(为了实现virtual函数,类中间必须要增加一个pointer指向虚函数表,这样增大了类的体积。所以没有必要的话,还是不要随意声明virtual的析构函数。普遍的规则是只有当类当中有virtual的函数时,析构函数才声明为vir

2013-12-12 01:10:25 674

原创 [LeetCode] Reorder List

Question: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},

2013-11-23 01:04:42 773

原创 [LeetCode] Binary Tree Preorder Traversal

Question:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: R

2013-11-22 02:26:51 856

原创 [LeetCode] Binary Tree Postorder Traversal

Question:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Re

2013-11-21 22:55:58 790

原创 [LeetCode] LRU Cache

Question:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of

2013-11-21 01:40:06 1182

原创 祝老婆生日快乐!

今天老婆生日,祝老怕生日快乐,永远开心幸福!留篇博客纪念下! I Love You!

2013-11-19 23:55:17 1199

原创 24点算法

计算24点最简单有效的方法就是递归穷举法。假如数组number[COUNT ]存放了要计算的数值(COUNT可以设为4或者其他)。算法基本思想:第一步:先从数组中选取两个数值number[i]和number[j],然后分别用"加/减/乘/除"进行计算,将得到的结果保存到数组中并替换number[i]的值,然后用数组最后一个值number[n-1]替换number[j]的值(即令numb

2013-11-19 00:26:17 1729

原创 KMP算法中的前缀函数

虽然在上一篇文章中已经全面介绍了KMP算法和前缀函数的计算过程。但是鉴于前缀函数的计算比较难以理解,这里再专门详细解释一下KMP算法中next[]数组的含义和实现过程,帮助加深理解。简单的说,前缀函数主要是求出模式串中的next数组,那么什么是模式串呢?模式串模式串的概念很简单。举个例子:“给出一个字符串 T,再给出 n 个字符串 S1、S2...Sn,问 S1、S2...Sn 中有哪些是

2013-11-18 00:48:58 3136 1

翻译 KMP算法总结

【KMP算法简介】          KMP算法是一种改进后的字符串匹配算法,由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。通过一个辅助函数实现跳过扫描不必要的目标串字符,以达到优化效果。   【传统字符串匹配算法的缺憾】          Bi

2013-11-17 21:00:29 1113

原创 [LeetCode] Implement strStr() 字符串子串

Question:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.Solution (C++):class Solution {public: char *s

2013-11-17 18:12:46 754

原创 [LeetCode] Spiral Matrix 螺旋输出矩阵

Question: 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

2013-11-17 01:55:29 1035

转载 C++中的smart pointer简单实现

Why Smart Pointer?为什么需要智能指针?因为c++的内存管理一直是个令人头疼的问题。假如我们有如下person对象:每个person有自己的名字,并且可以告诉大家他叫什么名字:////a person who can tell us his/her name.//#include#includeusing namespace std;clas

2013-11-16 22:46:53 1043

原创 指向继承类的基类指针解引用后,是否还具备多态性

指向继承类的基类指针解引用后,是否还具备多态性? 如下例:#include using namespace std;class Base{ public: int a; virtual void fun() { cout << "Base" << endl; }}; class Extend : public Base{ public: int b; vir

2013-11-16 22:24:50 1222

转载 类的对象和类的指针的区别

如下程序: #include  #include  using namespace std; class Student { public: static int number;  string name; public: Student() { } void set(string str) { name = str; 

2013-11-16 21:50:31 776

原创 微软面试题:反转二叉树

题目:给定一棵二叉树(1)将其反转,如下图所示。 (2)反转后的树如何实现左右通信。

2013-11-16 18:14:00 2975

原创 [LeetCode] Generate Parentheses

Question:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "(

2013-11-16 17:53:06 672

原创 [LeeCode] Insertion Sort List

Question:Sort a linked list using insertion sort.Solution:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x),

2013-11-16 05:23:07 780

原创 [LeetCode] 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.解法:游标指针从头节点向后移动,当指向尾节点时,得到链表长度len

2013-11-16 04:30:22 705

转载 [LeetCode]判断回文数(Palindrome Number)

题目来源:Leetcode(www.leetcode.com)Question:Determine whether an integer is a palindrome. Do this without extra space.Solution:First, the problem statement did not specify if negative in

2013-11-16 03:28:31 1109

原创 一道关于signed和unsigned的微软面试题

题目:unsigned int i=3;cout问输出结果是多少?我觉得大部分人的第一反应是-3。但是结果却不是这样的,写了个程序,运行了一下,输出结果是:4294967293。很诡异的一个数字,为什么会是这么个奇怪的数字呢?当你发现这数的十六进制数是FFFFFFFD时,你就离答案很近了... 这个涉及到了混合着不同数据类型的表达式中的数据类型的转换问题。在总结转换问题之前,

2013-11-15 15:43:21 995

原创 排序算法总结

一、冒泡排序基本思想是:两两比较相邻记录的关键字,如果反序则交换冒泡排序时间复杂度最好的情况为O(n),最坏的情况是O(n^2) 改进思路1:设置标志位,明显如果有一趟没有发生交换(flag = false),说明排序已经完成改进思路2:记录一轮下来标记的最后位置,下次从头部遍历到这个位置就Ok 二、直接插入排序将一个记录插入到已经排好序的有序表中, 从而得到一个新的,

2013-11-15 15:28:05 861

原创 判断两个矩形是否重叠/相交

题目:有两个矩形,别且已知两个矩形的左上角和右下角顶点的坐标值。如何判断两个矩形是否重叠/相交。分析:首先要明确一点,据题意,每个矩形只知道左上角和右下角的点,所以题目暗示(或者说默认)矩形的边与坐标轴平行,否则仅知两个顶点无法确定一个唯一的矩形。矩形A内的任意点(x,y),包括四边上的点,应满足如下不等式组Xa1 ≤ x ≤ Xa2   ①Ya1 ≤ y ≤ Ya

2013-11-15 15:20:55 5220

转载 有一亿个随机数,不排序如何找出其中位数

题目:在一个文件中有 10G个整数,乱序排列,要求找出中位数。内存限制为 2G。只写出思路即可(内存限制为 2G的意思就是,可以使用2G的空间来运行程序,而不考虑这台机器上的其他软件的占用内存)。 关于中位数:数据排序后,位置在最中间的数值。即将数据分成两部分,一部分大于该数值,一部分小于该数值。中位数的位置:当样本数为奇数时,中位数=(N+1)/2 ;当样本数为偶数时,中位数

2013-11-15 15:13:35 3330

原创 C++中 public,protected, private 访问标号

第一:private, public, protected 访问标号的访问范围。private:只能由1.该类中的函数、2.其友元函数访问。不能被任何其他访问,该类的对象也不能访问。protected:可以被1.该类中的函数、2.子类的函数、以及3.其友元函数访问。但不能被该类的对象访问。public:可以被1.该类中的函数、2.子类的函数、3.其友元函数访问,也可以由

2013-11-15 14:55:02 908

原创 最大堆(max-heap)和最小堆(min-heap)

在STL中,二叉堆是通过priority_queue的类模板实现的,标准头文件是。在STL中实现的是最大堆(max-heap)。成员函数有:void push (const Object & x);const Object & top() const;void pop();bool empty();void clear();优先队列模版用如下参数初始化:项类型,容器类型(几乎总

2013-11-15 14:51:40 8480

翻译 优先队列(堆)

优先队列和队列一样优先队列也支持入队和出队操作,不过区别在于优先队列的出队操作出队的是优先级最高的元素,这里以元素的大小来判定任务的优先级,越小,优先级越高。优先队列的模型如下图:                 基于这种优先队列的模型,我们可以多种方法对其进行实现,一种常用的方法就是使用链表以O(1)执行 插入操作,,遍历最小元素并删除花费O(N)时间。基于优先队列的

2013-11-15 00:51:37 1822

转载 AVL树的插入和删除

1. 概述AVL树是最早提出的自平衡二叉树,在AVL树中任何节点的两个子树的高度最大差别为一,所以它也被称为高度平衡树。AVL树得名于它的发明者G.M. Adelson-Velsky和E.M. Landis。AVL树种查找、插入和删除在平均和最坏情况下都是O(log n),增加和删除可能需要通过一次或多次树旋转来重新平衡这个树。本文介绍了AVL树的设计思想和基本操作。2. 基本术语

2013-11-13 19:31:58 2446

原创 寻找两个相交链表的第一个公共节点

Q:已知有两个链表,他们可能相交于某一点,求出该点。方法1. 最简单的方法就是先顺序访问其中一个链表,在每访问一个节点时,都对另外一个链表进行遍历,看节点是否相等  直到找到一个相等的节点位置,如果链表长度分别是m,n 则时间复杂度为O(mn);方法2. 对于第一个链表,每访问一个节点,对该节点做标记。访问第二个链表,如果该元素已经访问,则第一个这样的元素就是所求点。

2013-11-13 14:59:52 1030

翻译 检验某符号(如圆括号,方括号,花括号等)是否都成对出现

检验某个符号(如圆括号,方括号,花括号等)是否都成对出现。如,[()]是合法的,但[(])是非法的。这个算法的最简单方式是用栈实现,具体思路如下:做一个空栈。读入字符至文件尾。如果字符是一个开放符号,则将其压入栈中。如果字符是一个封闭符号那么若栈为空,则报错;若栈不为空,则将栈元素弹出。# 如果弹出的符号不是对应的开放符号,则报错。在文件尾,如果栈非空则

2013-11-13 14:45:43 1800

原创 中缀表达式转后缀表达式算法及实现—栈的应用

我们在数学中常见的计算式,例如2+(3*4)叫做中缀表达式。表达式中涉及到了多个运算符,而运算符之间是有优先级的。计算机在计算并且处理这种表达式时,需要将中缀表达式转换成后缀表达式,然后再进行计算。中缀表达式:0.3/(5*2+1) 的等价后缀表达式是:0.3 5 2 * 1 + /        中缀表达式转后缀表达式遵循以下原则:        1.遇到操作数,

2013-11-10 22:33:07 1398

原创 Reverse a string and reverse a sentence

#include #include #include #include #include //include reverse()#include using namespace std;int main(){ //用STL库里的函数reverse()翻转字符串; string str = "I love you!"; cout << "Original string:

2013-11-06 13:12:16 784

原创 The problem of Money Changes

/* * Input: n: the money you want to change; unit: starts with the maximum change's unit, e.g. 50 (if there are changes 1, 5, 10, 25, 50); Output: ways: the number of ways of chaning the mon

2013-11-06 01:53:02 681

原创 The number of nodes within k-hops in a n-D Torus

Torus is a widely used interconnection in high-performance computing systems. Torus can be built as 1D, 2D, 3D, 4D, 5D, 6D, and even higher dimensional topology, and they can be both server-centric an

2013-11-06 01:30:27 911

HiCut算法代码

HiCuts is the first decision tree-based packet classification algorithm. It takes the geometric view of the packet classification problem.

2013-11-16

给Shell初学者的入门知识

给Shell初学者的入门知识,简单易学通俗易懂。

2012-03-22

Linux系统命令及其使用详解(充电小王子)

Linux系统命令及其使用详解,通俗易懂,适合初学者和中级学者。

2012-03-22

OpenGL版俄罗斯方块

用OpenGL编写的俄罗斯方块,运行良好,界面也很不错。

2012-03-22

3D版俄罗斯方块源码

此为3D版游戏俄罗斯方块源码,供大家参考!

2012-03-22

网络拓扑发现程序

自己写的网络拓扑发现程序,Visual C++2008可完美运行

2012-03-22

OpenFlow and SDN-Network Substrade for the Cloud

OpenFlow and SDN-Network Substrade for the Cloud

2012-03-22

TCP/IP协议技术详解学习笔记

TCP/IP协议技术详解学习笔记,内容丰富详尽,通俗易懂。

2012-03-22

Openflow协议以及协议的代码实现

Openflow协议以及协议的代码实现,根据OpenFlow协议v1.0版本写。

2012-03-22

网络工程师必晓的网络经典命令

网络工程师必晓的网络经典命令,全面,经典,实用,实战。

2011-12-23

云计算入门指南

云计算入门指南,是一份非常不错的云计算入门资料!

2011-12-23

复数集合的运算C++实现

Filename : ComplexSet.cpp Intro : This is a Class of Set whoes elements are complex Functions: (1)The Union of two Sets (overload operator +,+=) (2)The Intersection of two Sets (overload operator *,*=) (3)The Difference of two Sets (overload operator -) (4)Add an element to a Set (5)Delete an element from a Set (6)Get the element which has the biggest module (7)Create a new Set (8)Output the elements of the Set (9)Get the amount of elements in ComplexSet (10)Judge if Set is empty or full (11)Find if the given element exist in the Set Author : Wang Ting Date : 2009-11 Language : C++

2011-05-22

用C++写的自动排课程序

用C++写的排课技术,This program realize the arragement of courses。

2011-05-22

自递归法解最大团问题

用自递归方法解决最大团问题,该方法属于exact algorithm。希望对大家有用。

2011-02-02

用遗传算法求方程极值

此程序为用遗传算法求方程极值,希望能对大家有用。

2010-12-09

空空如也

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

TA关注的人

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