自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 287. Find the Duplicate Number

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, fin

2016-10-05 21:26:31 271

原创 41. First Missing Positive

Given an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space.《剑

2016-10-05 20:54:45 214

转载 判定一棵二叉树是否是二叉搜索树

问题给定一棵二叉树,判定该二叉树是否是二叉搜索树(Binary Search Tree)?解法1:暴力搜索首先说明一下二叉树和二叉搜索树的区别。二叉树指这样的树结构,它的每个结点的孩子数目最多为2个;二叉搜索树是一种二叉树,但是它有附加的一些约束条件,这些约束条件必须对每个结点都成立:结点node的左子树所有结点的值都小于node的值。结点n

2016-09-29 00:09:22 754

转载 三色球排序

荷兰国旗题目描述拿破仑席卷欧洲大陆之后,代表自由,平等,博爱的竖色三色旗也风靡一时。荷兰国旗就是一面三色旗(只不过是横向的),自上而下为红白蓝三色。该问题本身是关于三色球排序和分类的,由荷兰科学家Dijkstra提出。由于问题中的三色小球有序排列后正好分为三类,Dijkstra就想象成他母国的国旗,于是问题也就被命名为荷兰旗问题(Dutch National Flag Problem)。下面是问题的

2016-09-28 23:57:46 1638

转载 求比正整数N大的最小正整数M,且M与N的二进制表示中有相同数目的1

转自http://blog.csdn.net/ligt0610/article/details/7262757一般最容易想到的方法就是先计算正整数N用二进制表示时1的个数count1,然后不停地计算N++用二进制表示时1的个数count2,直到碰到count1 == count2成立,代码如下:[cpp] view plain copy

2016-09-23 19:26:31 1857

原创 121. Best Time to Buy and Sell Stock I II III IV

121. Best Time to Buy and Sell StockSay 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 an

2016-09-13 11:35:28 264

原创 Path sum: four ways

#include <iostream>#include <vector>#include <queue>#include <map>using namespace std;#define VI vector<int>#define VII vector<vector<int> >VII dNext = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};class KV

2016-09-13 10:11:19 184

原创 120. Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7],

2016-09-12 21:54:39 130

转载 C/C++中的static关键字的总结

摘要: C/C++中static的2种设计和5种使用方法 面向过程程序设计中的static和面向对象程序设计中的static 具体应用的话,又涉及静态变量和静态函数两类 前者应用于普通变量(变量又分局部变量和全部变量)和函数,不涉及类;后者主要说明static在类中的作用。 因此结构关系如下,那么我们...C/C++中static的2种设计和5种使用方法面向过程程序设计中的

2016-09-07 21:54:47 228

转载 编辑距离 (Edit distance)

http://www.dreamxu.com/books/dsa/dp/edit-distance.html问题描述给定 2 个字符串 a, b. 编辑距离是将 a 转换为 b 的最少操作次数,操作只允许如下 3 种:插入一个字符,例如:fj -> fxj删除一个字符,例如:fxj -> fj替换一个字符,例如:jxj -> fyj思路用分治的思想解决比较简单,将复杂的问题分解成相似的子问题

2016-09-04 21:47:57 1921

原创 373. Find K Pairs with Smallest Sums

You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from the first array and one element from the second array.

2016-08-23 21:37:41 191

原创 382. Linked List Random Node

Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.Follow up: What if the linked list is extremely large and its le

2016-08-22 21:32:26 161

原创 29. Divide Two Integers

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.https://discuss.leetcode.com/topic/15568/detailed-explained-8ms-c-solutionIn this problem,

2016-08-07 11:25:01 182

原创 365. Water and Jug Problem

You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two ju

2016-07-31 11:42:17 222

原创 324. Wiggle Sort II

Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1,

2016-07-31 10:41:55 178

原创 71. Simplify Path

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases: Did you consider the case where path = “/../”? In th

2016-07-30 16:49:17 143

原创 375. Guess Number Higher or Lower II

We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you whether the number I picked is highe

2016-07-26 18:45:13 165

原创 368. Largest Divisible Subset

Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solutions, return

2016-07-26 17:57:15 162

原创 331. Verify Preorder Serialization of a Binary Tree

One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as #. _9

2016-07-23 10:43:08 185

原创 372. Super Pow

Your task is to calculate a^b mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8Example2:a = 2b = [1,0]R

2016-07-23 09:36:49 283

原创 376. Wiggle Subsequence

A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either posi

2016-07-22 12:31:14 260

原创 371 Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example: Given a = 1 and b = 2, return 3.转自 https://discuss.leetcode.com/topic/49771/java-simple-easy-un

2016-07-20 17:15:51 256

原创 43. Multiply Strings

Given two numbers represented as strings, return multiplication of the numbers as a string.Note:The numbers can be arbitrarily large and are non-negative.Convertingthe input string to integer is NOT

2016-06-30 22:08:42 327

原创 85. Maximal Rectangle

Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area.DP解法0th row: 0 0 0 1 0 0 0height: 0 0 0 1 0 0 0left: 0 0 0 3 0 0 0right 7 7 7 4 7

2016-06-28 21:07:32 171

原创 69. Sqrt(x)和367. Valid Perfect Square

69.Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.367.Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else Fal

2016-06-28 15:22:47 295

原创 139. Word Break

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, given s = "leetcode", dict = ["leet", "co

2016-06-16 17:28:35 213

转载 C++ 引用计数技术及智能指针的简单实现

本文转载自http://www.cnblogs.com/QG-whz/p/4777312.html正文一直以来都对智能指针一知半解,看C++Primer中也讲的不够清晰明白(大概是我功力不够吧)。最近花了点时间认真看了智能指针,特地来写这篇文章。1. 智能指针是什么简单来说,智能指针是一个类,它对普通指针进行封装,使智能指针类对象具有普通指针类型一样的操作。具体而言,复制对象时,副本和原对象都指向同

2016-06-15 10:35:08 252

原创 134. Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its nex

2016-06-14 22:31:55 183

原创 17. Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"O

2016-06-13 22:06:13 165

原创 330. Patching Array

Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Retur

2016-06-13 11:26:37 129

原创 3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the le

2016-05-30 20:51:12 457

原创 229. Majority Element II

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Hint: How many majority elements could it possibly ha

2016-05-27 17:18:58 143

转载 【机器学习】Logistic Regression 的前世今生(理论篇)

本文转自 http://blog.csdn.net/cyh_24/article/details/50359055侵删!写这篇博客的动力是源于看到了下面这篇微博:我在看到这篇微博的时候大为触动,因为,如果是rickjin来面试我,我想我会死的很惨,因为他问的问题我基本都回答不上来。所以,痛定思痛,我决定今后对一些算法的理解不能只是停留在表面,而应该至少往前推一步,尝

2016-05-25 15:07:49 796

原创 Ubuntu14.04安装编译ffmpeg

因为要用到improved dense trajectory特征,用源码需要编译ffmpeg和opencv,网址给出的源码需要的OpenCV-2.4.2 和ffmpeg-0.11.1都比较老,我用的是比较新的opencv2.4.12和ffmpeg-snapshot.tar.bz2 (2016-05-22)。本文主要基于此官方指导编译1. 安装依赖sudo apt-get updatesud

2016-05-23 16:11:08 8839 3

转载 Introduction to debugging neural networks

Introduction to debugging neural networksThe following advice is targeted at beginners to neural networks, and is based on my experience giving advice to neural net newcomers in industry and at Stanfor

2016-05-22 15:40:50 273

转载 转载:LeetCode:5Longest Palindromic Substring 最长回文子串

本文转自:http://www.cnblogs.com/TenosDoIt/p/3675788.html题目链接Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one

2016-05-22 15:39:33 208

原创 最长递增子序列

这是一道经典的动态规划题最长递增子序列问题:在一列数中寻找一些数,这些数满足:任意两个数a[i]和a[j],若i设dp[i]表示以i为结尾的最长递增子序列的长度,则状态转移方程为:dp[i] = max{dp[j]+1}, 1 1 int lengthOfLIS(vectorint>& nums) { 2 int size = nums.size();

2016-05-22 15:38:27 163

原创 321. Create Maximum Number 解题方法详解

321. Create Maximum Number题目描述 Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of

2016-05-22 15:37:03 422

原创 Ubuntu安装opencv with cuda

Ubuntu安装opencv with cuda为了运行dense flow真是折腾啊,下面网址是教程 http://blog.aicry.com/ubuntu-14-04-install-opencv-with-cuda/ http://rolflussi.blogspot.com/2015/09/opencv-with-cuda-on-ubuntu-1404.html 建议不要安装3.0

2016-05-22 15:35:57 680

原创 90. Subsets II

Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate s

2016-05-20 20:22:13 144

空空如也

空空如也

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

TA关注的人

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