6 寻路人davey

尚未进行身份认证

Deep Learning/图像处理

等级
博文 46
排名 9w+

快排、堆排序

快排:快速排序主要运用了二分的思想,每次选择一个基准元素,比基准元素打的元素都放在基准元素前面,比基准元素小的元素都放在基准元素后面,这样不断递归细分,完成排序。C++代码实现:voidQuickSort(inta[],intl,intr){inttemp=a[l];inti=l,j=r;if(l<r){while(i<j

2017-08-04 18:10:55

求二叉树深度、判断是否是平衡二叉树

求二叉树深度:递归的方法:从根节点按照先序顺序遍历二叉树,返回左子树和右子树中较大的深度,再加上1就是根节点的深度。C++代码实现:typedefstructTreeNode{intdata;structTreeNode*leftchild;structTreeNode*rightchild;}TreeNode,*Bitree;intTreeMaxDe

2017-08-04 13:55:53

数字在排序数组中出现的次数

题目:统计一个数字在排序数组中出现的次数。例如输入{1,2,3,3,3,3,4,5}和数字3,那么输出应该是4,因为3出现了4次。思路:直接暴力求解时间复杂度为O(n),下面利用二分查找的思想,给出时间复杂度为O(logn)的算法:1.利用二分查找的思想,找到第一个出现的K,时间复杂度为O(logn);2.利用二分查找的思想,找到最后一个出现的K,时间复杂度为O(logn)

2017-08-02 22:32:59

查找树中两个节点的最低公共祖先

求树中两个节点的最低公共祖先给定一棵树和两个节点,求解这两个节点在树中的最低公共祖先节点。(剑指Offer)思路:从根节点遍历树,直到要查找的节点,保存从根节点到要查找的节点的路径。遍历两次树,即保存了根节点到要查找的两个节点的两条路径,然后求出两条路径的最后一个交点即可。C++代码实现:#include<iostream>#include<vector>#include<list>u

2017-08-02 20:56:37

LeetCode -- 650. 2 Keys Keyboard

题目:Initiallyonanotepadonlyonecharacter‘A’ispresent.Youcanperformtwooperationsonthisnotepadforeachstep:CopyAll:Youcancopyallthecharacterspresentonthenotepad(partialcopy

2017-08-02 11:49:22

C语言中atoi()函数实现--字符串转int型整数

C语言中有个atoi()函数,将字符串转成整数,返回int类型的数值。思路很简单,但是有很多边界和细节要处理,本文参考剑指offer上的实例,仅供参考。#include<iostream>#include<string>enumStatus{kValid=0,kInValid};intg_nStatus=kValid;longlongstr2intCore(constch

2017-08-01 20:21:53

LeetCode -- 213. House Robber II

题目:Afterrobbingthosehousesonthatstreet,thethiefhasfoundhimselfanewplaceforhisthieverysothathewillnotgettoomuchattention.Thistime,allhousesatthisplacearearrangedina

2017-08-01 17:40:25

LeetCode -- 198. House Robber

题目:Youareaprofessionalrobberplanningtorobhousesalongastreet.Eachhousehasacertainamountofmoneystashed,theonlyconstraintstoppingyoufromrobbingeachofthemisthatadjacenthou

2017-08-01 16:28:47

LeetCode -- Range Sum Query - Immutable

题目:Givenanintegerarraynums,findthesumoftheelementsbetweenindicesiandj(i≤j),inclusive.Givennums=[-2,0,3,-5,2,-1]sumRange(0,2)->1sumRange(2,5)->-1sumRange(0,5)->-3No

2017-08-01 10:54:16

LeetCode -- 118. Pascal's Triangle

题目:GivennumRows,generatethefirstnumRowsofPascal’striangle.Forexample,givennumRows=5,Return[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]思路:本题主要考查vector的基本操作,杨辉三角形的计算

2017-07-26 21:53:53

LeetCode -- 88. Merge Sorted Array

题目:Giventwosortedintegerarraysnums1andnums2,mergenums2intonums1asonesortedarray.Note:Youmayassumethatnums1hasenoughspace(sizethatisgreaterorequaltom+n)toholdadditio

2017-07-26 21:15:06

LeetCode -- 66. Plus One

题目:Givenanon-negativeintegerrepresentedasanon-emptyarrayofdigits,plusonetotheinteger.Youmayassumetheintegerdonotcontainanyleadingzero,exceptthenumber0itself.Thedigits

2017-07-25 23:42:54

LeetCode -- 122. Best Time to Buy and Sell Stock II

题目:Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Designanalgorithmtofindthemaximumprofit.Youmaycompleteasmanytransactionsasyoulike(ie,buyon

2017-05-26 09:26:24

LeetCode -- 121. Best Time to Buy and Sell Stock

题目:Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Ifyouwereonlypermittedtocompleteatmostonetransaction(ie,buyoneandselloneshareofthestock),

2017-05-25 17:02:00

LeetCode -- 120. Triangle

题目:Givenatriangle,findtheminimumpathsumfromtoptobottom.Eachstepyoumaymovetoadjacentnumbersontherowbelow.Forexample,giventhefollowingtriangle[[2],[3,4],[6,5,7]

2017-05-25 16:12:31

LeetCode -- 96. Unique Binary Search Trees

题目:Givenn,howmanystructurallyuniqueBST’s(binarysearchtrees)thatstorevalues1…n?Forexample,Givenn=3,thereareatotalof5uniqueBST’s.13321\

2017-05-17 23:20:26

LeetCode -- 70. Climbing Stairs

题目:Youareclimbingastaircase.Ittakesnstepstoreachtothetop.Eachtimeyoucaneitherclimb1or2steps.Inhowmanydistinctwayscanyouclimbtothetop?Note:Givennwillbeapositive

2017-05-17 11:15:14

LeetCode -- 64. Minimum Path Sum

题目:Givenamxngridfilledwithnon-negativenumbers,findapathfromtoplefttobottomrightwhichminimizesthesumofallnumbersalongitspath.Note:Youcanonlymoveeitherdownorrightata

2017-05-17 11:00:03

LeetCode -- 63. Unique Paths II

题目:Followupfor“UniquePaths”:Nowconsiderifsomeobstaclesareaddedtothegrids.Howmanyuniquepathswouldtherebe?Anobstacleandemptyspaceismarkedas1and0respectivelyinthegrid

2017-05-17 10:21:01

LeetCode -- 62. Unique Paths

题目:Arobotislocatedatthetop-leftcornerofamxngrid(marked‘Start’inthediagrambelow).Therobotcanonlymoveeitherdownorrightatanypointintime.Therobotistryingtoreachthe

2017-05-17 09:41:31
奖章
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!