- 博客(34)
- 资源 (9)
- 收藏
- 关注
原创 LeetCode89/60 Gray Code/Permutation Sequence--迭代
一:Leetcode 89 Gray Code题目:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in
2015-04-20 14:51:40 1562
原创 相似图片搜索原理一(ahash—c++实现)
ahash,全称叫做average hash,应该是phash(perceptual hash, 感知哈希)算法的一种。是基于图像内容搜索最简单的一种(search image by image),因此也有很多的局限性。主要用于由图像的缩略图搜原图,对于图像的旋转、平移、对比度和微变形等都无能为力,所以很局限。此次讲解主要分为两个部分,理论部分主要参考是网上的资料,最核心的应该是自己的c++代
2015-04-17 20:45:25 8857 2
原创 离散余弦变换(C++实现)
理论部分转载自这篇blog: http://blog.csdn.net/luoweifu/article/details/8214959 该blog给出的是java代码,我用c++将其实现了。理论:图像处理中常用的正交变换除了傅里叶变换外,还有其他一些有用的正交变换,其中离散余弦就是一种。离散余弦变换表示为DCT( Discrete Cosine Transformation),
2015-04-17 20:01:56 5792
原创 最小二乘法和最大似然估计
一:背景:当给出我们一些样本点,我们可以用一条直接对其进行拟合,如y= a0+a1x1+a2x2,公式中y是样本的标签,{x1,x2,x3}是特征,当我们给定特征的大小,让你预测标签,此时我们就需要事先知道参数{a1,a2}。而最小二乘法和最大似然估计就是根据一些给定样本(包括标签值)去对参数进行估计参数估计的方法>。 二:最小二乘法:基本思想:简单地说,最小二乘的思想就是要使得观
2015-04-13 21:46:22 17564
原创 VC维
有关于VC维可以在很多机器学习的理论中见到,它是一个重要的概念。在读《神经网络原理》的时候对一个实例不是很明白,通过这段时间观看斯坦福的机器学习公开课及相关补充材料,又参考了一些网络上的资料(主要是这篇,不过个人感觉仍然没有抓住重点),重新思考了一下,终于理解了这个定义所要传达的思想。 先要介绍分散(shatter)的概念:对于一个给定集合S={x1, ... ,xd},如果一个假设类H能够
2015-04-13 20:54:23 3538
原创 LeetCode41/19 First Missing Positive/Remove Nth Node From End of List ****
leetcode41 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 algorit
2015-04-12 22:04:13 1174
原创 LeetCode 105/106 Construct Binary Tree from Preorder/Postorder and Inorder Traversal
一:LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates d
2015-04-12 13:59:02 1451
原创 LeetCode39/40/22/77/17/78/51/46/47/79 10道 Backtracking**
一: LeetCode39 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 nu
2015-04-12 12:25:32 1920
原创 LeetCode121/122/123/188 Best Time to Buy and Sell Stock<股票> I/II/III/IIII----DP+Greedy**
一:LeetCode 121 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 t
2015-04-11 20:30:13 2198
原创 LeetCode 55/45 Jump Game I/II-----Greedy**
一:Jump Game题目: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 length at that posi
2015-04-10 12:30:45 1310
原创 LeetCode 53/152 Maximum Subarray/Maximum Product Subarray---DP **
题目:Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguo
2015-04-09 16:57:42 1954
原创 LeetCode48/189 Rotate Image/Rotate Array
一: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?链接:https://leetcode.com/prob
2015-04-08 18:28:53 1100
原创 LeetCode 8题 --Array+Binary search**
这5道题都是array的binary search就可以搞定了分别是leetcode(35)——Search Insert Position leetcode(33)——Search in Rotated Sorted Array leetcode(81)——Search in Rotated Sorted Array II leetcode(34)——Search fo
2015-04-07 14:49:43 1120
转载 LeetCode73 Set Matrix Zeroes**
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a b
2015-04-07 09:19:38 1595
原创 LeetCode54/59 Spiral Matrix I/II
一:Spiral Matrix I题目: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
2015-04-06 20:23:18 1909
原创 LeetCode 62/63/120/64 Unique PathsI/II Triangle/Min sum Path/Rectangle Area--DP
一:unique Path题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot i
2015-04-06 15:49:37 1321
原创 LeetCode78/90 subset I/II**
一:Unique paths I题目: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 duplic
2015-04-06 15:22:22 2010
原创 LeetCode66/169/79 Plus One/Majority Element /Word Search
一: Plus One题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.
2015-04-05 21:37:17 1059
原创 LeetCode26/27/80/75 Remove Duplicates from Sorted Array I and II/Remove Element/Set Colors**
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in pla
2015-04-05 20:38:14 1160
原创 LeetCode12~14 Integer to Roman/Roman to Integer/Longest Common Prefix
一:Integer to Roman题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.链接:https://leetcode.com/problems/integer-to-roman/分析:此题
2015-04-05 15:43:42 1036
原创 LeetCode7~9 Reverse Integer/String to Integer (atoi)/Palindrome Number
一:Reverse Integer题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321链接:https://leetcode.com/problems/reverse-integer/分析:这题通过不断取余将余数存放在一个vecto
2015-04-05 13:39:58 1102
原创 LeetCode2 Add Two Numbers
题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it
2015-04-04 20:17:29 1084
原创 LeetCode1/16/15/18 Two Sum/3Sum/3Sum Closest/4Sum**
题目:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the targ
2015-04-03 19:37:51 1302
原创 LeetCode42/11 Trapping Rain Water/Container With Most Water/Hist area**
题目地址:https://leetcode.com/problems/trapping-rain-water/这道题关键点是是两边往中间遍历,记录当前第二高点secHeight,然后利用这个第二高点减去当前历经的柱子,剩下就装水容量了。为什么是第二高点?因为两边比较,最高的点不用动,只移动第二高点。这也是阿里2015实习生招聘附加题第三题class Solution {publi
2015-04-03 11:23:26 1012
原创 LeetCode4/88 Median of Two Sorted Arrays/Merge Sorted Array
题目地址:https://leetcode.com/problems/median-of-two-sorted-arrays/这道题就是求两个有序序列的中位数。这也是2015年4月阿里实习生招人附加题第一题我用的是归并算法,时间复杂度和空间复杂度都为O(M+N)class Solution {public: double findMedianSortedArrays(int
2015-04-03 10:23:13 1056
原创 LeetCode69 Sqrt(x)**
链接地址:https://leetcode.com/problems/sqrtx/这道题就是求一个数的平方根我这里提供三种方法1:大家都知道平方根一定都是[1,x/2]之间,所以从1循环到x/2, 但当x=1是通过的,不是好方法而且会TLEclass Solution { // TLE而且不精确public: int sqrt(int x) { in
2015-04-03 10:17:40 4800
原创 leetCode 101/199-Symmetric Tree/Binary Tree Right Side View
链接:https://leetcode.com/problems/symmetric-tree/此题就是判断一棵二叉树是否为对称二叉树,刚开始以为中序遍历输出,然后看是否是为回文字串,但是这种思路是错了,如[1,2,3,#,3,#,2].代码如下:通过循环递归判断左孩子的左子树与右孩子的右子树 及 左孩子的右子树与右孩子的左子树即可得到结果。class Solution {pub
2015-04-02 18:40:13 1207
转载 struct 字节对齐详解与大小端模式
一.什么是字节对齐,为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这就需要各种类型数据按照一定的规则在空间上排列,而不是顺序的一个接一个的排放,这就是对齐。 对齐的作用和原因:各个硬件平台对存储空间的处理上有很大的不同。一些平台对某些特定类型的
2015-04-02 14:17:57 7468
原创 leetCode 98-Validate Binary Search Tree
题目链接:https://leetcode.com/problems/validate-binary-search-tree/就是判断一个给定的二叉树是否为二叉查找树。我的思路是:先将该树中序遍历一遍,按中序遍历的顺序保存到一个vector中,然后判断vector中的顺序即可。代码:class Solution {public: void inOrder(TreeNode
2015-04-02 09:24:02 1757
原创 逆序数的几种求法
逆序数就是指比如:数组A={2,4,3,5}那么就是一个逆序数。一:暴力匹配对于数组A中的元素,i从0到n-1,j从i+1到n, 判断每一个是否为逆序数,时间复杂度O(lgN)。太简单了,没写代码了。。。。。二:归并归并排序能解决逆序数主要在于:比如归并A1={2,4,5}, A2={1,3},进行归并的时候,我们每次判断A1和A2中元素大小,这里有两种思路:(1)当A1[i] ,
2015-04-01 21:20:30 4766
原创 树状数组与线段树
一:树状数组 树状数组是对一个数组改变某个元素和求和比较实用的数据结构。两中操作都是O(logn)。需求:有时候我们需要频繁地求数组的前k项和或者求数组从小标i到j的和,这样每次最坏情况下的时间复杂度就会为O(N),这样效率太低了。而树状数组主要就是为了解决这样一个问题。树状数组在求和及修改都可以在O(lgN)时间内完成。 树状数组需要额外维护一个数组,我们设为
2015-04-01 20:38:11 1615
原创 leetCode 190-Reverse Bits
链接: https://leetcode.com/problems/reverse-bits/此题的关键是预先将1class Solution {public: Solution(){ unsigned int i = 0; unsigned int j = 1; for(; i < 32; i++) a[i] = (j<<(31-i)); }
2015-04-01 19:11:40 1669
原创 leetCode191/201/202/136 -Number of 1 Bits/Bitwise AND of Numbers Range/Happy Number/Single Number
链接:https://leetcode.com/problems/number-of-1-bits/此题关键是如何判断一个数字的第i为是否为0 即: x& (1class Solution {public: int hammingWeight(uint32_t n) { int count = 0; for(int i = 0; i < 32;
2015-04-01 18:32:00 1737
原创 leetCode198-House Robber
链接:https://leetcode.com/problems/house-robber/这道理可以看做是状态压缩,每两个数字看做是一行,状态有3个,故需要F[N][3]的数组,F[i][j]就表示第i行状态j时rob的money。具体状态压缩可以看我这两篇blog: 算法练习系列—hiho1048 状态压缩一(铺地砖) 算法练习系列—hiho1044 状态压缩二(捡垃圾)#inc
2015-04-01 18:28:58 8483
图片检索(均匀hash,感知hash,颜色直方图)
2015-05-17
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人