E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
面试算法
leetcode:Remove Nth Node From End of List(删除链表倒数第n个节点)【
面试算法
题】
题目:Givenalinkedlist,removethe nth nodefromtheendoflistandreturnitshead.Forexample,Givenlinkedlist:1->2->3->4->5,andn=2. Afterremovingthesecondnodefromtheend,thelinkedlistbecomes1->2->3->5. Note:Given
zhang9801050
·
2013-10-21 21:00
LeetCode
list
链表
指针
end
of
leetcode:Remove Element (删除给定元素)【
面试算法
题】
题目:Givenanarrayandavalue,removeallinstancesofthatvalueinplaceandreturnthenewlength.Theorderofelementscanbechanged.Itdoesn'tmatterwhatyouleavebeyondthenewlength.题意把数组中与给定值相同的元素删除,在原数组上修改,返回值是最终元素个数。将没有
zhang9801050
·
2013-10-20 19:00
LeetCode
element
remove
删除元素
leetcode:Remove Duplicates from Sorted List II (留下链表中只出现一次的元素)【
面试算法
题】
题目:Givenasortedlinkedlist,deleteallnodesthathaveduplicatenumbers,leavingonly distinct numbersfromtheoriginallist.Forexample,Given 1->2->3->3->4->4->5,return 1->2->5.Given 1->1->1->2->3,return 2->3.题意要
zhang9801050
·
2013-10-20 13:00
leetcode:Remove Duplicates from Sorted List(去除链表中重复元素)【
面试算法
题】
题目:Givenasortedlinkedlist,deleteallduplicatessuchthateachelementappearonly once.Forexample,Given 1->1->2,return 1->2.Given 1->1->2->3->3,return 1->2->3.题意去掉链表中重复的元素。主要就是链表的删除操作,判断当前节点是否和前一个节点值相同,如果相同就
zhang9801050
·
2013-10-20 11:00
LeetCode
去重
链表
leetcode:Remove Duplicates from Sorted Array II (允许重复一次,去掉数组多余数字)【
面试算法
题】
题目:Followupfor"RemoveDuplicates":Whatifduplicatesareallowedatmost twice?Forexample,GivensortedarrayA= [1,1,1,2,2,3],Yourfunctionshouldreturnlength= 5,andAisnow [1,1,2,2,3].题意每个数只允许重复一次,输出去重后的数组和个数,依旧上
zhang9801050
·
2013-10-19 16:00
LeetCode
面试算法
leetcode:Remove Duplicates from Sorted Array(去掉数组重复数字,常数空间限制)【
面试算法
题】
题目:Givenasortedarray,removetheduplicatesinplacesuchthateachelementappearonly once andreturnthenewlength.Donotallocateextraspaceforanotherarray,youmustdothisinplacewithconstantmemory.Forexample,Givenin
zhang9801050
·
2013-10-19 15:00
leetcode:Recover Binary Search Tree (修正二叉查找树错误节点,不改变结构)【
面试算法
题】
题目:Twoelementsofabinarysearchtree(BST)areswappedbymistake.Recoverthetreewithoutchangingitsstructure.Note:AsolutionusingO(n)spaceisprettystraightforward.Couldyoudeviseaconstantspacesolution?confusedwha
zhang9801050
·
2013-10-19 11:00
LeetCode
tree
二叉树
search
binary
中序遍历
leetcode:Pow(x, n) (计算x的n次方) 【
面试算法
题】
题目:Implementpow(x, n).题意计算x的n次方,考虑复杂度和n的取值。n有可能是正数或者负数,分开计算。用递归的做法讲复杂度降到O(logn)。classSolution{ public: doublepow(doublex,intn){ if(n==0)return1; if(n==1)returnx; doubletemp=pow(x,abs(n/2)); if(n>0) {
zhang9801050
·
2013-10-18 15:00
LeetCode
次方
leetcode:Populating Next Right Pointers in Each Node II (顺序连接二叉树每一层节点)【
面试算法
题】
题目:Followupforproblem"PopulatingNextRightPointersinEachNode".Whatifthegiventreecouldbeanybinarytree?Wouldyourprevioussolutionstillwork?Note:Youmayonlyuseconstantextraspace.Forexample,Giventhefollowing
zhang9801050
·
2013-10-18 10:00
LeetCode
二叉树
指针
leetcode:Populating Next Right Pointers in Each Node(常数空间,连接二叉树每一层所有节点)【
面试算法
题】
题目:GivenabinarytreestructTreeLinkNode{ TreeLinkNode*left; TreeLinkNode*right; TreeLinkNode*next; } Populateeachnextpointertopointtoitsnextrightnode.Ifthereisnonextrightnode,thenextpointershouldbesetto
zhang9801050
·
2013-10-17 17:00
LeetCode
二叉树
DFS
leetcode:Plus One (加一)【
面试算法
题】
题目:Givenanumberrepresentedasanarrayofdigits,plusonetothenumber.题意动态数组存了一些个位数字,组成一个大数,计算这个大数加一之后的值。模拟大数的加法,当没有进位的时候就可以弹出循环。特殊考虑各个位数就是9的情况,加一后会多出一位,即结果是1加上len个0,len是digits的长度。classSolution{ public: vect
zhang9801050
·
2013-10-17 17:00
LeetCode
one
Plus
大数加法
leetcode:Permutations (序列所有排列)【
面试算法
题】
题目:Givenacollectionofnumbers,returnallpossiblepermutations.Forexample,[1,2,3] havethefollowingpermutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],and [3,2,1].题意输出给定序列的所有排列。用dfs去遍历所有可能的序列,data记录结果
zhang9801050
·
2013-10-17 15:00
LeetCode
DFS
Permutations
leetcode:Permutation Sequence (顺序排列第k个序列) 【
面试算法
题】
题目:Theset [1,2,3,…,n] containsatotalof n!uniquepermutations.Bylistingandlabelingallofthepermutationsinorder,Wegetthefollowingsequence(ie,for n =3):"123""132""213""231""312""321"Given n and k,returnthe
zhang9801050
·
2013-10-17 15:00
LeetCode
sequence
permutation
leetcode:Path Sum II (路径之和,记录结果路径)【
面试算法
题】
题目:Givenabinarytreeandasum,findallroot-to-leafpathswhereeachpath'ssumequalsthegivensum.Forexample:Giventhebelowbinarytreeand sum=22,5 /\ 48 //\ 11134 /\/\ 7251 return[ [5,4,11,2], [5,8,4,5] ] 题意找到所有路径
zhang9801050
·
2013-10-16 16:00
LeetCode
递归
路径记录
leetcode:Path Sum (路径之和) 【
面试算法
题】
题目:Givenabinarytreeandasum,determineifthetreehasaroot-to-leafpathsuchthataddingupallthevaluesalongthepathequalsthegivensum.Forexample:Giventhebelowbinarytreeand sum=22,5 /\ 48 //\ 11134 /\\ 721 return
zhang9801050
·
2013-10-16 16:00
LeetCode
递归
leetcode:Pascal's Triangle II (杨辉三角形,空间限制)【
面试算法
题】
题目:Givenanindex k,returnthe kth rowofthePascal'striangle.Forexample,given k =3,Return [1,3,3,1].Note:Couldyouoptimizeyouralgorithmtouseonly O(k)extraspace?题意输出杨辉三角形第k行,空间限制为O(k)。循环利用当前数组,用上一行相邻两个数值和做当
zhang9801050
·
2013-10-15 23:00
LeetCode
杨辉三角形
leetcode: Pascal's Triangle (杨辉三角形) 【
面试算法
题】
题目:Given numRows,generatethefirst numRows ofPascal'striangle.Forexample,given numRows =5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意给出行数,输出对应的杨辉三角形。按题意用动态数组处理,除了最后一个数,其他数都是上一行相邻两个数的和。clas
zhang9801050
·
2013-10-15 22:00
LeetCode
杨辉三角形
leetcode:Partition List (链表处理)【
面试算法
题】
题目:Givenalinkedlistandavalue x,partitionitsuchthatallnodeslessthan x comebeforenodesgreaterthanorequalto x.Youshouldpreservetheoriginalrelativeorderofthenodesineachofthetwopartitions.Forexample,Given
zhang9801050
·
2013-10-15 22:00
LeetCode
链表
支付宝
面试算法
题
所谓的对称数如12321,23432等整数,用C语言设计一个算法,输入一个整数,判断其是否对称数算法如下:boolis_wanted(constunsignedp_data){unsigneddata=p_data;unsignednew_data=0;while(data/10){new_data*=10;new_data+=data%10;data/=10;if(data<10){new_da
迷茫的量子
·
2013-10-13 07:33
Linux
leetcode:Palindrome Partitioning (字符串分割成回文串的所有方式) 【
面试算法
题】
题目:Givenastring s,partition s suchthateverysubstringofthepartitionisapalindrome.Returnallpossiblepalindromepartitioningof s.Forexample,given s = "aab",Return[ ["aa","b"], ["a","a","b"] ] 题意把给定的字符串分割,
zhang9801050
·
2013-09-30 11:00
LeetCode
dp
partition
DFS
palindrome
回文串
leetcode:Palindrome Number (判断数字是否回文串) 【
面试算法
题】
题目:Determinewhetheranintegerisapalindrome.Dothiswithoutextraspace.Somehints:Couldnegativeintegersbepalindromes?(ie,-1)Ifyouarethinkingofconvertingtheintegertostring,notetherestrictionofusingextraspace
zhang9801050
·
2013-09-29 22:00
LeetCode
数字
number
palindrome
回文串
leetcode:Next Permutation (求下一个排列) 【
面试算法
题】
题目:Implementnextpermutation,whichrearrangesnumbersintothelexicographicallynextgreaterpermutationofnumbers.Ifsucharrangementisnotpossible,itmustrearrangeitasthelowestpossibleorder(ie,sortedinascendingo
zhang9801050
·
2013-09-29 21:00
leetcode:N-Queens II (n皇后问题2)【
面试算法
题】
题目:FollowupforN-Queensproblem.Now,insteadoutputtingboardconfigurations,returnthetotalnumberofdistinctsolutions.题意输出n×n的皇后棋子布局有多少种不同的情况。和上题一样的思路,只是不需要输出图,每次满足条件的时候记录一下次数。introw[1000]; intcol[1000]; int
zhang9801050
·
2013-09-29 17:00
【有趣的
面试算法
题】之四 求最小不重复数,源于百度2014届校园招聘软件研发岗位深圳站
百度2014届校园招聘软件研发岗位深圳站的笔试中有这样一题:输入一个任意正整数,输出一个比输入值要大但又不重复的最小数(不重复是指:相邻两个数字不相同,例如1101是重复,1234不重复,1201不重复),比如输入1234,应当输出1235,而不是1232、1236、4321等。分析思路:一,考虑数值区间。尽量选择一个容器比较大的类型,以便不溢出,unsignedlonglong就比较适
zfdxx369
·
2013-09-29 16:00
算法
面试
百度
校园招聘
软件研发
leetcode:N-Queens (n皇后问题) 【
面试算法
题】
题目:The n-queenspuzzleistheproblemofplacing n queensonan n×n chessboardsuchthatnotwoqueensattackeachother.Givenaninteger n,returnalldistinctsolutionstothe n-queenspuzzle.Eachsolutioncontainsadistinctbo
zhang9801050
·
2013-09-29 16:00
LeetCode
N皇后
N-Queens
Minimum Window Substring(最小覆盖子串)【
面试算法
题】
leetcode:MinimumWindowSubstring(最小覆盖子串)【
面试算法
题】分类: leetcode
面试算法
题2013-09-2702:29 305人阅读 评论(0) 收藏 举报leetcodeMinimumWindowSubstring
pi9nc
·
2013-09-27 22:00
leetcode面试算法题
leetcode:Multiply Strings(字符串的乘法)【
面试算法
题】
题目:Giventwonumbersrepresentedasstrings,returnmultiplicationofthenumbersasastring.Note:Thenumberscanbearbitrarilylargeandarenon-negative.题意给两个字符串表示的数字,计算他们的乘积。其实就是手写一个大数乘法,先翻转字符串便于从低位开始计算。模拟乘法的运算过程,把中间
zhang9801050
·
2013-09-27 11:00
LeetCode
大数乘法
leetcode:Minimum Window Substring(最小覆盖子串)【
面试算法
题】
题目:GivenastringSandastringT,findtheminimumwindowinSwhichwillcontainallthecharactersinTincomplexityO(n).Forexample,S = "ADOBECODEBANC"T = "ABC"Minimumwindowis "BANC".Note:IfthereisnosuchwindowinSthatco
zhang9801050
·
2013-09-27 02:00
LeetCode
window
substring
Minimum
最小覆盖子串
leetcode:Minimum Path Sum(路线上元素和的最小值)【
面试算法
题】
题目:Givena m x n gridfilledwithnon-negativenumbers,findapathfromtoplefttobottomrightwhich minimizes thesumofallnumbersalongitspath.Note: Youcanonlymoveeitherdownorrightatanypointintime.题意从左上到右下,所有可能的路径
zhang9801050
·
2013-09-27 01:00
LeetCode
动态规划
leetcode:Minimum Depth of Binary Tree(树的根节点到叶子节点的最小距离)【
面试算法
题】
题目:Givenabinarytree,finditsminimumdepth.Theminimumdepthisthenumberofnodesalongtheshortestpathfromtherootnodedowntothenearestleafnode.题意求到叶子节点最短的距离。递归遍历,注意必须要到叶子节点,中间的节点不能算。/** *Definitionforbinarytree
zhang9801050
·
2013-09-26 00:00
LeetCode
递归
tree
binary
depth
Minimum
leetcode:Merge Two Sorted Lists (链接两个有序链表)【
面试算法
题】
题目:Mergetwosortedlinkedlistsandreturnitasanewlist.Thenewlistshouldbemadebysplicingtogetherthenodesofthefirsttwolists.题意链接两个有序链表。没啥难点,注意头指针的建立和空指针。/** *Definitionforsingly-linkedlist. *structListNode{
zhang9801050
·
2013-09-26 00:00
LeetCode
链表
指针
leetcode:Merge Sorted Array(合并两个有序数组到其中一个数组中)【
面试算法
题】
题目:GiventwosortedintegerarraysAandB,mergeBintoAasonesortedarray.Note:YoumayassumethatAhasenoughspacetoholdadditionalelementsfromB.ThenumberofelementsinitializedinAandBare m and n respectively.题意要把两个有序
zhang9801050
·
2013-09-25 23:00
LeetCode
array
merge
sorted
leetcode:Merge k Sorted Lists(按大小顺序连接k个链表)【
面试算法
题】
题目:Merge k sortedlinkedlistsandreturnitasonesortedlist.Analyzeanddescribeitscomplexity.题意:把k个排序成一个有序链表。用优先队列先把k个链表遍历一遍把值存起来,在建一个新链表吧数从优先队列里一个个放进去,注意空指针的判断。/** *Definitionforsingly-linkedlist. *structL
zhang9801050
·
2013-09-25 23:00
LeetCode
链表
lists
merge
sorted
leetcode:Merge Intervals(合并相交集合) 【
面试算法
题】
题目:Givenacollectionofintervals,mergealloverlappingintervals.Forexample,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].题意把相交的集合合并。按start排序,遍历的时候判断前后集合是否有相交,如果没有就把之前的集合输出。/** *Definitionfo
zhang9801050
·
2013-09-25 18:00
LeetCode
merge
Intervals
合并集合
leetcode:Median of Two Sorted Arrays (找两个序列的中位数,O(log (m+n))限制) 【
面试算法
】
题目:TherearetwosortedarraysAandBofsizemandnrespectively.Findthemedianofthetwosortedarrays.TheoverallruntimecomplexityshouldbeO(log(m+n)).题意已只两个有序的序列,找到他们的中位数,复杂度要求O(log(m+n))。问题可以转化成两个有序序列找第num大的数,用类似二
zhang9801050
·
2013-09-25 16:00
LeetCode
Arrays
sorted
中位数
Two
Median
leetcode:Maximum Subarray(最大的连续子数组) 【
面试算法
】
题目:Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray [−2,1,−3,4,−1,2,1,−5,4],thecontiguoussubarray [4,−1,2,1] hasthelargestsum= 6.题意求连续的子
zhang9801050
·
2013-09-23 22:00
LeetCode
贪心
连续子数组
leetcode:Maximum Depth of Binary Tree(计算二叉树深度) 【
面试算法
】
题目:Givenabinarytree,finditsmaximumdepth.Themaximumdepthisthenumberofnodesalongthelongestpathfromtherootnodedowntothefarthestleafnode.查找二叉树的深度,递归去做,注意判断边界就好了。/** *Definitionforbinarytree *structTreeNod
zhang9801050
·
2013-09-21 19:00
LeetCode
递归
二叉树
Maximal Rectangle (求矩阵的最大的子矩阵) 【
面试算法
leetcode】
题目:Givena2Dbinarymatrixfilledwith0'sand1's,findthelargestrectanglecontainingallonesandreturnitsarea.题意有一个01组成的矩阵,找到其中面积最大的,全部由1构成的子矩阵。去年做多校比赛的时候第一次见到这题,不优化到O(n×n)死活过不了当时。优化就是先预处理成保存成,当前点向上都是1的最高的高度,就变
zhang9801050
·
2013-09-21 17:00
LeetCode
rectangle
Maximal
最大的子矩阵
Longest Valid Parentheses(最长的括号匹配)【
面试算法
leetcode】
题目:Givenastringcontainingjustthecharacters '(' and ')',findthelengthofthelongestvalid(well-formed)parenthesessubstring.For "(()",thelongestvalidparenthesessubstringis "()",whichhaslength=2.Anotherexam
zhang9801050
·
2013-09-21 16:00
LeetCode
最长的括号匹配
leetcode:Longest Substring Without Repeating Characters (双指针扫描) 【
面试算法
题】
题目:Givenastring,findthelengthofthelongestsubstringwithoutrepeatingcharacters.Forexample,thelongestsubstringwithoutrepeatinglettersfor"abcabcbb"is"abc",whichthelengthis3.For"bbbbb"thelongestsubstringis
zhang9801050
·
2013-09-21 15:00
LeetCode
substring
longest
Without
Repeating
面试算法
Longest Palindromic Substring (最长回文串)【
面试算法
leetcode】
题目:Givenastring S,findthelongestpalindromicsubstringin S.Youmayassumethatthemaximumlengthof S is1000,andthereexistsoneuniquelongestpalindromicsubstring.题意寻找并输出字符串中的最长回文串。没想到什么特别好的算法,就上暴力加些剪枝。枚举回文串的长度,
zhang9801050
·
2013-09-21 15:00
LeetCode
substring
longest
Palindromic
回文串
Longest Consecutive Sequence (最长连续序列) 【
面试算法
leetcode】
题目:Givenanunsortedarrayofintegers,findthelengthofthelongestconsecutiveelementssequence.Forexample,Given [100,4,200,1,3,2],Thelongestconsecutiveelementssequenceis [1,2,3,4].Returnitslength: 4.Youralgor
zhang9801050
·
2013-09-21 14:00
LeetCode
sequence
longest
Consecutive
最长连续序列
leetcode:Distinct Subsequences (不同的子序列)【
面试算法
题】
题目:Givenastring S andastring T,countthenumberofdistinctsubsequencesof T in S.Asubsequenceofastringisanewstringwhichisformedfromtheoriginalstringbydeletingsome(canbenone)ofthecharacterswithoutdisturbin
zhang9801050
·
2013-09-17 23:00
LeetCode
distinct
动态规划
subsequence
不同的子序列
百度
面试算法
1、实现一个函数,对一个正整数n,算得到1需要的最少操作次数。操作规则为:如果n为偶数,将其除以2;如果n为奇数,可以加1或减1;一直处理下去。例子:func(7)=4,可以证明最少需要4次运算n=7n-16n/23n-12n/21要求:实现函数(实现尽可能高效)intfunc(unsignintn);n为输入,返回最小的运算次数。给出思路(文字描述),完成代码,并分析你算法的时间复杂度。答:[c
Jfans
·
2013-09-17 18:00
面试算法
之排序算法集锦
排序算法在面试过程中是经常会考的,这是很基础的,面试官觉得你应该很熟悉这些东西,如果你半个小时内写不出来,那基本就给跪了,因为这真的是狠基础狠基础的东西,所以我们得对一些基本的排序算法烂熟于胸,对这些排序思想,效率了如指掌,才能让面试官觉得你还行。基本的排序算法有:直接插入排序,冒泡排序,简单选择排序,shell排序,归并排序,快速排序,堆排序。其中归并,快速,堆排序是面试时候比较喜欢考的,因为这
anonymalias
·
2013-09-11 03:00
排序
面试算法
之排序算法集锦
排序算法在面试过程中是经常会考的,这是很基础的,面试官觉得你应该很熟悉这些东西,如果你半个小时内写不出来,那基本就给跪了,因为这真的是狠基础狠基础的东西,所以我们得对一些基本的排序算法烂熟于胸,对这些排序思想,效率了如指掌,才能让面试官觉得你还行。基本的排序算法有:直接插入排序,冒泡排序,简单选择排序,shell排序,归并排序,快速排序,堆排序。其中归并,快速,堆排序是面试时候比较喜欢考的,因为这
anonymalias
·
2013-09-11 03:00
算法
面试
排序算法
面试算法
之排序算法集锦
排序算法在面试过程中是经常会考的,这是很基础的,面试官觉得你应该很熟悉这些东西,如果你半个小时内写不出来,那基本就给跪了,因为这真的是狠基础狠基础的东西,所以我们得对一些基本的排序算法烂熟于胸,对这些排序思想,效率了如指掌,才能让面试官觉得你还行。基本的排序算法有:直接插入排序,冒泡排序,简单选择排序,shell排序,归并排序,快速排序,堆排序。其中归并,快速,堆排序是面试时候比较喜欢考的,因为这
iteye_18480
·
2013-09-11 03:00
面试
数据结构与算法
shell
面试算法
之链表操作集锦
链表操作在面试过程中也是很重要的一部分,因为它和二叉树一样都涉及到大量指针的操作,而且链表本身很灵活,很考查编程功底,所以是很值得考的地方。下面是本文所要用到链表节点的定义:template structListNode{ Typedata; ListNode*next; };链表的创建可以采用下面的代码,采用尾插法进行链表的创建,返回的链表没有头节点:/** *Createalist,witho
anonymalias
·
2013-09-04 21:00
算法
链表
面试算法
之二叉树操作集锦
开学了,找工作也正式拉开了序幕,每天光自己看书,也很没劲,和大家一起分享分享,交流一下笔试面试过程中的各种算法题目,如有问题,欢迎指正,希望大家一起进步。。。下面是对数据结构二叉树的一些基本操作,可能在面试中都会涉及到。我们都知道二叉树的定义本身就是一种递归定义,所以对树的大部分操作都可以通过递归的方式进行,但递归不是万能的,因为递归的本身是一件很浪费内存资源的操作,所以在选择算法的时候要权衡各种
anonymalias
·
2013-09-03 17:00
二叉树
【有趣的
面试算法
题】之三 求最大子序列和/积问题,关注起点和终点
最大子序列和的问题,网上讨论得比较多,较为推崇的复杂度为O(n)的算法: intmaxSubSum(int*a,intn,int*seqStart=0,int*seqEnd=0) { intmaxSum=0; intthisSum=0; for(inti=0,j=0;jmaxSum) { maxSum=thisSum; *seqStart=i; *seqEnd=j; } elseif(this
zfdxx369
·
2013-08-20 13:00
算法
面试
上一页
25
26
27
28
29
30
31
32
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他