自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Search in Rotated Sorted Array II(leetcode)

题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]

2014-11-29 16:49:58 419

原创 Set Matrix Zeroes (leetcode)

题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution

2014-11-29 15:48:33 420

原创 Simplify Path(leetcode)

题目:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:

2014-11-29 15:24:20 559

原创 Valid Number(leetcode)

题目:Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to b

2014-11-29 11:45:09 560

原创 auto_ptr与异常抛出

下面这个代码是没有用auto_ptr的,这个当fun1()函数被调用,且参数传递为0时,会抛出异常,这个异常抛出以后就会终端这个函数接下来的执行,这样,就会导致fun1()函数中的delete p;的操作无法进行,进而导致内存泄露。#include#include using namespace std;class A{ int num;public: A() { num

2014-11-29 11:41:16 532

原创 24点游戏

《编程之美》1.16 24点游戏输入:n1,n2,n3,n4。输出:若能得到运算结果为24,则输出一个对应的运算表达式,否则输出0。例如:输入11,8,3,5,则输出为:(11-8)*(3+5)=24。思想:四个数总共有五种结合方式,即A(B(CD))、A((BC)D)、(AB)(CD)、(A(BC))D、((AB)C)D,而我把这五种次序存入保存计算顺序的二维数组sequence中,每次

2014-11-29 11:05:35 724

原创 构造数独

《编程之美》1.15节:构造数独构造一个9*9的矩阵,其中每一行都是1-9,每一列也是1-9,9个3*3的子方格中也是1-9。解:用回溯法,往当前格中填数字,如果满足就进行下一个格子,如果不满足就尝试下一个数,如果9个数都不满足,就回溯到前一个方格中,用下一个数继续尝试。#include#includeusing namespace std;//判断行、列和3*3的格中是否有重

2014-11-26 22:28:59 686

原创 NIM(3)两堆石头的游戏

《编程之美》1.13节:NIM(3)两堆石头的游戏题目:假设有两堆石头,有两个玩家会根据如下的规则轮流去石头:没人每次可以从两堆石头中各取出数量相等的石头,或者仅从一对石头中取出任意数量的石头;最后把剩下的石头一次拿光的人获胜。解:把两堆石头的数目用列表列出,找出其中的不安全点,而能够一步到达这种不安全点的地方都是安全点。进而根据不安全点找出规律。规律:一般而言,第n组的不安全局面(an,

2014-11-26 21:17:10 1003

原创 函数返回类时调用构造函数次数

#includeusing namespace std;class A{ int m;public: A(int m=0) { cout<<"一般构造函数\n"; } A(const A &a) { m=a.m; cout<<"拷贝构造函数\n"; } void operator =(const A &a) { this->m=a.m; cout<<

2014-11-26 20:11:56 1546 1

原创 类中static成员变量定义和声明

类中static成员变量的定义和声明:在VS2010中,只能在类外定义同时赋值,在类中声明。不能再类中声明时赋值!!#includeusing namespace std;class A{public: static int a; static int b;};int A::a=1;int A::b=1;int main() { cout<<A::a<<en

2014-11-26 19:25:49 3411

原创 C++容器元素遍历的问题

C++容器遍历可以用容器的迭代器来完成,但是像vector、dequeue等线性容器可以用[]来索引,迭代方式如下:#include#includeusing namespace std;int main() { vector temp(10,1); //有警告:unsigned int和int不匹配 for(int i=0;i<temp.size();i++) co

2014-11-26 19:06:53 1563

转载 C++库常用函数一览表

本文中提到的函数库有: 1.   标准C++库字符串类std::string的用法begin       得到指向字符串开头的Iteratorend         得到指向字符串结尾的Iteratorrbegin      得到指向反向字符串开头的Iteratorrend        得到指向反向字符串结尾的Iteratorsize        得到字符串的

2014-11-26 19:01:45 1700

原创 Spiral Matrix II(leetcode)

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

2014-11-26 16:03:34 425

原创 Spiral Matrix (leetcode)

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

2014-11-26 15:43:06 572

转载 锁相环原理和应用

1、锁相环名称是锁相,而锁相的前提是锁频,因为频率不同的信号,是无法保持恒定的相位差的。2、此外,锁相环是一个闭环跟踪系统,如果将输入信号M分频,输出信号就跟随分频后的信号,即M分频输出;如果将反馈信号N分频,输出信号就N倍频。利用这一点,可以产生分频信号、倍频信号及分数倍频信号。以下摘自:http://blog.sina.com.cn/s/blog_4a248863010005mc.ht

2014-11-26 10:44:46 27814 3

转载 卡尔曼滤波

下面转自:http://blog.csdn.net/newthinker_wei/article/details/11768443过程方程:X(k+1) =  A X(k) + B U(k) + W(k)               >>>>式1量测方程:Z(k+1) =  H X(k+1)+ V(k+1)                  >>>>式2

2014-11-26 10:40:03 4215

原创 NIM(2)"拈"游戏分析

《编程之美》第1.12节:NIM(2)"拈"游戏分析如果石头总数N是偶数,则后动手的人能赢;如果石头数时奇数,则先动手的人赢,先动手的人只要保证每次取完石头以后,每堆石头的总数异或后得1即可。下面程序给出当N是奇数时,应该如何选取,函数返回值pair中first表示取第i堆,i从0开始,second表示把第i堆变成的数,即剩下的数时divided[i]-second。#include

2014-11-25 22:14:14 684

原创 Substring with Concatenation of All Words(leetcode)

题目:You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and

2014-11-25 20:20:41 536

原创 NIM(1)一排石头的游戏

《》

2014-11-25 11:30:11 858

转载 auto_ptr解析

auto_ptr解析auto_ptr是当前C++标准库中提供的一种智能指针,或许相对于boost库提供的一系列眼花缭乱的智能指针,这个不怎么智能的智能指针难免会黯然失色。诚然,auto_ptr有这样那样的不如人意,以至于程序员必须像使用”裸“指针那样非常小心地使用它才能保证不出错,以至于它甚至无法适用于同是标准库中的那么多的容器和一些算法,但即使如此,我们仍然不能否认这个小小的auto_ptr

2014-11-24 22:07:15 390

原创 高效的安排见面会

《编程之美》第1.9节

2014-11-24 21:48:59 478

原创 Regular Expression Matching(leetcode)

题目:

2014-11-24 19:09:54 452

原创 设置浏览器不显示图片

由于学校每个

2014-11-24 14:52:20 1279

原创 Max Points on a Line(leetcode)

题目:

2014-11-24 14:44:25 436

原创 Find Minimum in Rotated Sorted Array II (leetcode)

题目:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at som

2014-11-22 11:39:52 398

原创 Find Minimum in Rotated Sorted Array(leetcode)

题目:

2014-11-22 11:06:59 430

原创 Min Stack(leetcode)

题目:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top(

2014-11-21 22:36:20 563

原创 小飞的电梯调度算法

《编程之美》

2014-11-21 22:06:37 542

原创 Maximum Product Subarray (leetcode)

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

2014-11-21 22:04:25 503

原创 Evaluate Reverse Polish Notation (leetcode)

题目:

2014-11-21 17:31:31 397

原创 求逆序数(光影切割问题)

《编程之美》第1.7

2014-11-21 09:43:30 623

原创 Sort List(leetcode)

题目:题目来源:https://oj.leetcode.com/problems/sort-list/解题思路:如果有O(n)的额外空间的话就先拷贝出来,用vector排序后再拷回去,如果必须原址排序就需要用mergeSort进行排序了。O(n)的额外空间时:

2014-11-20 19:42:26 464

原创 Insertion Sort List(leetcode)

题目:

2014-11-20 16:46:05 439

转载 如何选择到最好女孩

求一个数列的逆序数逆序对:数列a[1],a[2],a[3]…中的任意两个数a[i],a[j] (i,如果a[i]>a[j],那么我们就说这两个数构成了一个逆序对逆序数:一个数列中逆序对的总数如数列 3 5 4 8 2 6 9(5,4)是一个逆序对,同样还有(3,2),(5,2),(4,2)等等那么如何求得一个数列的逆序数呢?方法1:一个一个的数

2014-11-20 16:30:35 894

原创 LRU Cache (leetcode)

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

2014-11-20 16:14:30 527

原创 饮料供货

就 Volume,int N,int V[],int C[],int H

2014-11-19 22:01:19 493

原创 Binary Tree Postorder Traversal (leetcode)

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

2014-11-19 15:35:58 435

原创 快速找出故障机器

编程珠玑》

2014-11-18 22:14:39 389

原创 一摞烙饼的排序

《编程之美》1.3节:主要是

2014-11-18 21:40:55 520

原创 Binary Tree Preorder Traversal(leetcode)

题目: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].

2014-11-18 18:59:17 366

空空如也

空空如也

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

TA关注的人

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