自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode: Best Time to Buy and Sell Stock III

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 two transactions.Note:You may

2014-12-25 16:23:19 389

原创 leetcode:Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2014-12-24 20:44:23 426

原创 leetcode:Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in

2014-12-23 14:57:10 904

原创 leetcode:Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element

2014-12-22 22:55:35 742

原创 求最长等差数列

// 最长等差数列.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include using namespace std;int max(int a, int b){ if (a >= b) return a; return b;}int getMax

2014-12-21 15:25:56 586

原创 leetcode: Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {public: void rotate(vect

2014-12-15 21:38:49 358

转载 白话经典算法系列之七 堆与堆排序

转自:http://blog.csdn.net/morewindows/article/details/6709644 堆排序与快速排序,归并排序一样都是时间复杂度为O(N*logN)的几种常见排序方法。学习堆排序前,先讲解下什么是数据结构中的二叉堆。二叉堆的定义二叉堆是完全二叉树或者是近似完全二叉树。二叉堆满足二个特性:1.父结点的键值总是大于或等

2014-12-15 16:42:42 401

转载 poj 3984 迷宫问题 —— 典型搜索--DFS递归

转自:http://blog.csdn.net/u012099869/article/details/11610497四个方向,每次选择一个方向走,不通时走下一个方向,如果四个方向都不能走时,则退一格。依题意,可用DFS递归实现。#include#includeint n,m,i,j,k,flag,count;int data[5][5],vis[5][5];

2014-12-15 15:26:19 1145 2

转载 求随机数构成的数组中找到长度大于或等于3的最长的等差数列

转自:http://www.cnblogs.com/eric-blog/archive/2012/05/04/2483402.html输出等差数列由小到大?如果没有符合条件的就输出“NO”。例如: 输入[1,3,0,5,-1,6] ,输出[-1,1,3,5] 。要求:时间复杂度,空间复杂度尽量小解体思路:设随机数为a[],首先排序,(1)枚举两个

2014-12-14 21:48:50 1019

转载 STL算法系列

http://blog.csdn.net/jerryjbiao/article/category/870957

2014-12-14 20:49:40 392

转载 正确释放Vector的内存

转自出处: http://blog.jobbole.com/37700/今天在看微博的时候, 有人提出了一个对于Vector内存泄露的疑问( Link)。博主采用 Vector存储一些数据,但是发现在执行 clear() 之后内存并没有释放,于是怀疑产生了内存泄露。随后有人回复:“vector 的 clear 不影响 capacity , 你应该 swap 一个

2014-12-14 20:39:01 378

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

2014-12-13 17:27:18 363

转载 leetcode: Permutation Sequence

转自出处:http://www.cnblogs.com/tenosdoit/p/3721918.htmlLeetCode:Permutation Sequence题目链接The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all

2014-12-13 15:08:18 401

原创 leetcode: Same Tree

Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./**

2014-12-12 15:00:19 328

原创 leetcode: Reverse Linked List II

Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the

2014-12-12 14:49:11 341

转载 常见的概率相关面

转自:http://www.acmerblog.com/interviews-about-probability-5359.html在笔记题中概率相关的数学题,也有部分编程题,出现的还是挺多的。概率在生活中的应用较多,同时也可以综合考查面试者的思维能力、应变能力、数学能力。在这里整理了一些概率相关的笔试题和大家分享,此文不涉及编程题,都是一些和生活相关且很有趣的概率题。所有的分

2014-12-12 12:39:43 652

转载 三个枪手的博弈(转)

转自出处:http://breeze-159.blog.163.com/blog/static/3913984220098594354512/三个枪手的博弈(转)  2009-09-05 21:43:54|  分类: 转|举报|字号 订阅今天,看面试题目的时候,看到一道很有趣的题目,关于三个枪手的问题:      三个枪手

2014-12-12 12:16:15 7445

转载 归并排序c++代码及详细注释

转自:http://www.cnblogs.com/hxf829/archive/2008/11/18/1659863.html#include using namespace std;template void MSort(T a[], int left, int right){ if (left < right) { int

2014-12-11 20:03:27 7627

原创 Subsets

Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.class

2014-12-11 14:59:48 420

原创 leetcode: Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is

2014-12-11 11:57:09 357

原创 Insertion Sort List

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

2014-12-11 11:25:45 418

转载 一个很好的有关概率问题的帖子

转自 : http://www.cnblogs.com/orchid/p/4067042.html1,一根木棒,截成三截,组成三角形的概率是多少?2,抛一个六面的色子,连续抛直到抛到6为止,问期望的抛的次数是多少?3,一个木桶里面有M个白球,每分钟从桶中随机取出一个球涂成红色(无论白或红都涂红)再放回,问将桶中球全部涂红的期望时间是多少?4,你有一把宝剑

2014-12-10 23:20:27 2574

转载 讲解

转自出处:http://supercharles888.blog.51cto.com/609344/1345561其实这道题就是 :   在一个数组中找出和为10的所有组合的问题题目:假设有一个大水池,其容积为poolSize,还有n个彼此大小不同的水桶,分别是B1,B2,B3,B4,B5..Bn,放在一个数组中 。请给出水桶的所有组合,使得他们的容

2014-12-10 22:27:37 516

转载 数组al[0,mid-1]和 al[mid,num-1],都分别有序。将其merge成有序数组al[0,num-1],要求空间复杂度O(1)

转自 : 数组al[0,mid-1]和 al[mid,num-1],都分别有序。将其merge成有序数组al[0,num-1],要求空间复杂度O(1)思路:由于要求空间复杂度为O(1),故不能使用归并排序1、遍历0~mid -1,将其与a[mid]相比较,若 a[mid] 2、循环遍历a[mid~length],如果1中交换后a[mi

2014-12-10 17:20:53 1260

转载 A的大小为n,其中的每相邻的两个元素之间差的绝对值为1,例如A={4 5 6 5 6 7 8 9 10 9},给定A和t,设计一个程序,求出t在A中的位置

转自:http://www.mianwww.com/html/2014/04/20571.htmlA的大小为n,其中的每相邻的两个元素之间差的绝对值为1,例如A={4 5 6 5 6 7 8 9 10 9},给定A和t,设计一个程序,求出t在A中的位置题目:A的大小为n,其中的每相邻的两个元素之间差的绝对值为1,例如A={4 5 6 5 6 7 8 9 10

2014-12-10 16:14:25 1462

转载 库函数memcpy()与memmove()实现

转自 :http://www.cppblog.com/zenliang/articles/131782.html根据MSDN文档,当源区域与目标区域存在重叠时,memcpy()函数报错,而memmove()函数可以处理重叠情况! 1/*  2 * 函数名: memcpy  3 * 功  能: 从源source中拷贝n个字节到目标destin中  4 * 用  法

2014-12-10 16:06:45 408

转载 单遍历取等概率随机数问题

转自 : http://happyprince.iteye.com/blog/1488318问题描述:假设我们有一堆数据(可能在一个链表里,也可能在文件里),数量未知。要求只遍历一次这些数据,随机选取其中的一个元素,任何一个元素被选到的概率相等。O(n)时间,O(1)辅助空间(n是数据总数,但事先不知道)。 引例:5个人抽5个签,只有一个签意味着

2014-12-10 14:48:46 1517

转载 一个概率题:54张扑克牌,除去两张大小王剩下52张扑克牌。问红桃A和黑桃A同时被一个人拿到的概率是多少?

转自:http://www.cnblogs.com/yunfei181/archive/2010/12/08/1900367.html任意排列的种数有C(52,13)*C(39,13)*C(26*13)其中两个A在一家的种数为C(4,1)*C(50,11)*C(39,13)*C(26*13)因此概率为C(4,1)*C(50,11)*C(39,13)*C(26*1

2014-12-10 14:32:19 12353

转载 有n个长为m+1的字符串,如果某个字符串的最后m个字符与某个字符串的前m个字符匹配,则两个字符串可以联接

转自: http://www.cnblogs.com/tractorman/p/4065544.html算法中的三重循环第三重的意思是假设现在要求  1, 3  两个节点可拼接的最大距离先看 :  1:0    1:1   1:2   1:3   1:4                0:3   1:3    2:3   3:3   4:3

2014-12-10 14:27:29 1987

转载 计数排序,基数排序和桶排序

转自 :http://www.cnblogs.com/ttltry-air/archive/2012/08/04/2623302.html计数排序,基数排序,桶排序等非比较排序算法,平均时间复杂度都是O(n)。这些排序因为其待排序元素本身就含有了定位特征,因而不需要比较就可以确定其前后位置,从而可以突破比较排序算法时间复杂度O(nlgn)的理论下限。计数排序(Count

2014-12-09 23:39:15 463

转载 一个小猴子边上有100根香蕉,它要走过50米才能到家,每

转自出处:http://tieba.baidu.com/p/263036091516根. 问题简化成走最短的路,背更多的水果.但路和水果之间有限制! 题目已经限制,猴子最多背50,我们计算其消耗仅剩下50根的米处, 假设猴子第一次背了50根,走了X米,在回来搬第2个50根,就有: 100-3X ......... 剩下的香蕉数(先走X,往反2X) 50-X

2014-12-09 22:23:31 12011

原创 leetcode: Word Ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m

2014-12-09 14:59:00 402

原创 Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},

2014-12-09 12:14:49 322

原创 leetcode: 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 retur

2014-12-09 11:53:37 337

原创 leetcode:Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary

2014-12-08 23:51:42 280

转载 iOS多线程编程Part 3/3 - GCD

转自出处:http://www.hrchen.com/2013/07/multi-threading-programming-of-ios-part-3/iOS多线程编程Part 3/3 - GCD前两部分介绍了NSThread、NSRunLoop和NSOperation,本文聊聊2011年WWDC时推出的神器GCD。GCD: Grand Central Dispa

2014-12-08 22:56:45 420

转载 iOS多线程编程Part 2/3 - NSOperation

转自出处:http://www.hrchen.com/2013/06/multi-threading-programming-of-ios-part-2/iOS多线程编程Part 2/3 - NSOperation多线程编程Part 1介绍了NSThread以及NSRunLoop,这篇Blog介绍另一种并发编程技术:NSOPeration。NSOperation

2014-12-08 22:54:50 418

转载 iOS多线程编程Part 1/3 - NSThread & Run Loop

转自:http://www.hrchen.com/2013/06/multi-threading-programming-of-ios-part-1/iOS多线程编程Part 1/3 - NSThread & Run Loop前言多线程的价值无需赘述,对于App性能和用户体验都有着至关重要的意义,在iOS开发中,Apple提供了不同的技术支持多线程编程,除了跨平

2014-12-08 22:53:24 482

转载 NSRunLoop Internals

转自出处:https://mikeash.com/pyblog/friday-qa-2010-01-01-nsrunloop-internals.htmlFriday Q&A 2010-01-01: NSRunLoop Internalsby Mike Ash  It's the first Friday of the new year, and that me

2014-12-08 22:51:59 433

原创 上台阶,上三下二

一个寺庙有N个台阶,一个人站在下面,他要去到第M个台阶,假设他只有2个方案可以选择 1. 向上走3台阶 2. 向下走2个台阶。请问他到达第M个台阶最少要走多少步。给出核心算法并分析复杂度// taijie_up3_down2.cpp : Defines the entry point for the console application.//#include "stdafx.h

2014-12-08 11:56:54 627

空空如也

空空如也

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

TA关注的人

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