自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

不积跬步无以至千里

不积跬步无以至千里

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

原创 纯虚函数小记

#include using namespace std; class a{public: virtual void f()=0;};void a::f(){//纯虚函数也可以被定义(虽然通常不这么做),只不过必须放在类的外部 cout<<"class a";}class b:public a{public: void f() override{ cout<<"

2015-11-30 21:49:53 341

原创 具有默认实参的虚函数及虚函数回避机制

struct B{ virtual void f1(string str="base"){ cout<<str<<endl; }};struct D:B{ void f1(string str) override{//此时重写的函数可以没有默认实参 cout<<str<<endl; }};当基类和派生类中的虚函数的默认实参不一致时,动态绑定不会作用在实参上,换句话

2015-11-30 19:55:55 724 3

原创 OpenCV笔记(三)

#include#include#includeusing namespace cv;#define WINDOW "Image"//opencv没有按钮功能,常用滚动条代替int g_pVal;//滚动条当前值int g_max;//滚动条最大值Mat redImage;Mat tmpImage;void callFunc(int, void* ){ auto it=t

2015-11-30 19:28:11 487

原创 c++11 final与override说明符

//final,override出现在形参列表以及尾置返回类型之后#include using namespace std;struct B{ virtual void f1(int) const; virtual void f2(int); void f3(int) final;//final不能修饰非虚函数};struct D:B{ void f1(int) const ov

2015-11-29 21:21:33 453

原创 OpenCV笔记(二)

#include#includeusing namespace cv;int main(){ std::cout<<CV_VERSION;//opencv版本 //Mat redImage(500,500,CV_8U);//定义尺寸和类型 Mat redImage; redImage=imread("redflo.bmp"); namedWindow("redImage",CV_W

2015-11-29 19:59:03 667

原创 Best 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. You may complete at most k transactions.Note:You may

2015-11-28 22:06:46 292

原创 OpenCV笔记(一)

#includeusing namespace cv;int main(){ Mat srcImage=imread("flo.bmp",1); pyrDown(srcImage,srcImage); imshow("flowers",srcImage); Mat element = getStructuringElement(MORPH_RECT,Size(15,15));//返回

2015-11-27 20:43:43 1137

原创 Combination Sum III

Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi

2015-11-26 21:21:11 283

原创 Combination Sum II

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina

2015-11-26 20:56:06 247

原创 Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb

2015-11-25 21:57:22 252

原创 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./** * Definition for singly-link

2015-11-24 13:49:01 251

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

2015-11-24 12:56:13 241

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

2015-11-23 21:25:49 225

原创 Bulls and Cows

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t

2015-11-22 13:41:20 273

原创 Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther

2015-11-21 11:29:32 283

原创 标准库function类型的小例子

#include#include#include#includeusing namespace std;int add(int a,int b){ return a+b;}struct divide{ int operator()(int a,int b){ return a/b; }};int main(){ auto mod=[](const int&a,con

2015-11-20 19:26:40 434

原创 c++图像处理:24位真彩图颜色变换

#include#includeusing namespace std;bool isred(BYTE r,BYTE g,byte b){ if(r>=0&&r<=255&& g>=0&&g<=150&& b>=0&&b<=150) return true; else return false;}void red2green(BYTE& r,BYTE& g,BYTE&

2015-11-20 16:07:57 2356

原创 Additive Number

Additive number is a positive integer whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent num

2015-11-19 18:07:21 362

原创 几个lamda表达式

#include#include#include#includeusing namespace std;int main(){ char* a[]={"abc","asdaf","afsdagherws","abrrc","qweqweqweqweqwe","ab"}; vectorv(a,a+6); sort(v.begin(),v.end(),[](char* a,cha

2015-11-19 14:05:23 539

原创 Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]

2015-11-17 14:16:51 311

原创 快速排序(找主元)

著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 给定划分后的N个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?例如给定N = 5, 排列是1、3、2、4、5。则:1的左边没有元素,右边的元素都比它大,所以它可能是主元;尽管3的左边元素都比它小,但

2015-11-16 19:02:59 4451

原创 考试座位号

输入格式:输入第一行给出一个正整数N(考生信息之后,给出一个正整数M(输出格式:对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用1个空格分隔。输入样例:410120150912233 2 410120150912119 4 110120150912126 1 310120150912002 3 223 4

2015-11-16 13:48:26 1065

原创 素数对猜想

让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数。显然有 d1=1 且对于n>1有 dn 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。现给定任意正整数N (5),请计算不超过N的满足猜想的素数对的个数。输入格式:每个测试输入包含1个测试用例,给出正整数N。输出格式:每个测试用例的输出占一行,不超过N的满足猜想的素数对的个数。

2015-11-16 13:26:42 424

原创 换个格式输出整数

让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(输入格式:每个测试输入包含1个测试用例,给出正整数n(输出格式:每个测试用例的输出占一行,用规定的格式输出n。输入样例1:234输出样例1:BBSSS1234输入样例2:23输出样例2:SS123#include#include#includeu

2015-11-16 13:04:07 343

原创 继续(3n+1)猜想

卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对n=3进行验证的时候,我们需要计算3、5、8、4、2、1,则当我们对n=5、8、4、2进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这4个数已经在验证3的时候遇到过了,我们称5、8、4、2是被

2015-11-16 12:44:42 321

原创 (3n+1)猜想

卡拉兹(Callatz)猜想:对任何一个自然数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)砍掉一半。这样一直反复砍下去,最后一定在某一步得到n=1。卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证(3n+1),以至于有人说这是一个阴谋,卡拉兹是在蓄意延缓美国数学界教学

2015-11-15 16:51:23 649

原创 Populating Next Right Pointers in Each Node II

Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant

2015-11-14 14:57:01 227

原创 Populating Next Right Pointers in Each Node

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.

2015-11-14 11:26:50 230

原创 Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each

2015-11-13 19:22:57 189

原创 Search a 2D Matrix II

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in

2015-11-13 19:13:36 227

原创 Spiral Matrix II

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, 4 ], [

2015-11-13 18:36:16 209

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

2015-11-13 12:30:16 243

原创 Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at

2015-11-13 10:31:41 207

原创 Generate Parentheses

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:"((()))", "(()())", "(())()", "()(())", "()()

2015-11-12 21:24:27 227

原创 Range Sum Query 2D - Immutable

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).The above rectangle (with the red bo

2015-11-12 15:31:42 249

原创 find duplicate

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,

2015-11-12 11:11:04 312

原创 Range Sum Query - Immutable

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan

2015-11-11 11:15:16 278

原创 coins in a line

有 n 个硬币排成一条线。两个参赛者轮流从右边依次拿走 1 或 2 个硬币,直到没有硬币为止。拿到最后一枚硬币的人获胜。请判定 第一个玩家 是输还是赢?您在真实的面试中是否遇到过这个题? Yes样例n = 1, 返回 true.n = 2, 返回 true.n = 3, 返回 false.n = 4, 返回 true.n = 5,

2015-11-10 13:17:12 276

原创 add-and-search-word

Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only

2015-11-09 22:08:30 260

原创 implement-trie

Implement a trie with insert, search, and startsWith methods.注意You may assume that all inputs are consist of lowercase letters a-z.class TrieNode {public: bool has; TrieNode*

2015-11-09 13:27:14 247

空空如也

空空如也

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

TA关注的人

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