自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 资源 (5)
  • 收藏
  • 关注

原创 【数学】Count Primes

题目:leetcodeCount PrimesDescription:Count the number of prime numbers less than a non-negative number, n分析:求出比n小的素数的个数,这个问题可以用排除法做,参考http://www.cnblogs.com/grandyang/p/4462810.html

2015-04-28 19:13:04 671

原创 临时变量与复制构造函数(二)

为了直观观察,以下代码中复制构造函数会把成员变量num+1class B{ int num;public: B():num(0){ cout << "默认构造函数" << " num= "<< num <<endl; } B(int n) :num(n){ cout << "带参构造函数" << " num= " << num << endl; } B(const

2015-04-23 10:30:43 732

原创 临时变量与复制构造函数

class B{public: B(){ cout << "构造函数" << endl; } B(const B &b) { cout << "复制构造函数" << endl; } ~B() { cout << "析构函数" << endl; }};B play(B b){ return b;}main函数输入如下代码:{ B b

2015-04-23 09:23:59 992

原创 【数学】约瑟夫环问题中,最后剩下的人是第几个人

题目:约瑟夫环问题中,最后剩下的人是第几个人。如一共4个人,数到2的人出列,最后剩下的那个人是第1个人,返回1.int Josephus(int n, int k){ if (n<=0 || k<1) throw exception(); if (n==1) return 1;//人为规定,n为1时返回1 int res=k%2;//只有两个人时,返回的人的下标(从零开

2015-04-22 10:45:31 2847

转载 【位操作】Bitwise AND of Numbers Range

题目:leetcodeBitwise AND of Numbers RangeGiven a range [m, n] where 0 For example, given the range [5, 7], you should return 4.参考:http://www.cnblogs.com/lailailai/p/4430972.html分析:对[

2015-04-16 11:06:48 343

原创 【回溯法】Permutations II

题目:leetcodePermutations II Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique perm

2015-04-15 19:38:12 564

原创 【回溯法】Sudoku Solver

题目:leetcodeSudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be on

2015-04-15 18:43:46 850

转载 【字符串匹配】Implement strStr()

题目:leetcodeImplement strStr() Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.参考:http://www.tuicool.com/arti

2015-04-15 11:09:36 478

原创 Text Justification

题目:leetcodeText JustificationGiven an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack

2015-04-14 18:30:38 452

原创 【哈希、动态规划】Edit Distance

题目:leetcodeEdit Distance Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the fo

2015-04-13 18:23:07 467

原创 【栈、动态规划】Longest Valid Parentheses

题目:leetcodeLongest Valid ParenthesesGiven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the l

2015-04-13 15:30:04 609

原创 【动态规划+滚动数组】Interleaving String

题目:leetcodeInterleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcb

2015-04-10 18:05:22 664

原创 【广度优先遍历】Number of Islands

题目:leetcodeNumber of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent l

2015-04-10 10:19:56 573

转载 【广度优先遍历】Word Ladder II

题目:leetcodeWord Ladder II Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be change

2015-04-07 10:21:07 584

原创 【哈希表】Longest Consecutive Sequence

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

2015-04-06 16:00:27 562

原创 【动态规划】Dungeon Game

题目:leetcodeDungeon Game The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid.

2015-04-05 22:43:15 550

转载 【动态规划】Best Time to Buy and Sell Stock IV

题目:leetcodeBest Time to Buy and Sell Stock IV Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit.

2015-04-03 14:50:35 531

原创 【贪婪算法、动态规划】Jump Game II

题目:leetcodeJump Game II Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump

2015-04-01 15:33:17 885

VC++程序: 将字符串转换成公式并计算结果

int Calculate(string formula) 函数功能:输入一个字符串公式string formula,允许四则混合运算,然后输入公式中对应变量的取值,最后返回int类型计算结果。 变量的格式:必须由1位字母加1位数字组成,如a1、b2等。 如输入字符串 “(a1+b2)/(-100)”,以及a1=100,b2=300,得到结果-4。遇到小数则向下取整。 公式的格式: 1、只包含变量、常数、四则符号、小括号四种符号,不支持大括号和中括号 2、允许正数前加正号,如+100 3、不允许空括号,如 “8*( )” 4、允许负数,但负数必须加括号,如 "5/(-1)"。当负数在公式开头时,可不加括号, 如 "-a1+90"和“+a1+90” 都是对的 5、允许纯常数公式,如 “5*(-9)” 6、允许用户输入多余的空格,但空格不能造成公式错误, 如公式 “(1 08+a2)/a 3” 是错的,(- 7)和(- n5)是错的,去掉空格就对了。

2014-10-23

求字符的所有排列

求字符的全排列,如输入三个字符a、b、c,则它们的组合有a,b,c,ab,ac,bc,abc。

2014-06-08

判断二叉搜索树的前序遍历

《剑指offer》面试题24的相关题目。输入一个整数数组,判断该数组是不是某二叉搜索树的前序遍历。假设输入的数组的任意两个数字互不相同。

2014-06-08

从上到下打印二叉树结点

用队列实现从上到下打印二叉树每个节点,同一层的节点按照从左到右的顺序打印。用C++实现。

2014-06-08

N皇后问题C++代码

N皇后问题C++代码

2014-06-07

空空如也

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

TA关注的人

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