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_C++
leetcode_c++
:哈希: Happy Number(202)
Writeanalgorithmtodetermineifanumberis“happy”.Ahappynumberisanumberdefinedbythefollowingprocess:Startingwithanypositiveinteger,replacethenumberbythesumofthesquaresofitsdigits,andrepeattheprocessuntilt
LandscapeMi
·
2023-10-25 11:01
leetcode(c++)
Leetcode_C++
之200. Number of Islands(岛屿数量)
题目名称NumberofIslands题目描述Givenanmxn2Dbinarygridgridwhichrepresentsamapof'1’s(land)and'0’s(water),returnthenumberofislands.Anislandissurroundedbywaterandisformedbyconnectingadjacentlandshorizontallyorver
JayShaun
·
2022-12-20 13:27
leetcode
leetcode
c++
算法
Leetcode_c++
: Maximal Rectangle (085)
题目Givena2Dbinarymatrixfilledwith0’sand1’s,findthelargestrectanglecontainingallonesandreturnitsarea.算法http://www.cnblogs.com/felixfang/p/3676193.html有了上一题的基础,这道题就可等效为上一题,对于矩阵每一行,我们将其看作直方图,立柱的高度就是行中元素往上
LandscapeMi
·
2020-09-15 17:10
leetcode(c++)
leetcode_c++
:图:Reconstruct Itinerary (332)
http://www.cnblogs.com/grandyang/p/5183210.htmlclassSolution{public:vectorfindItinerary(vector>tickets){vectorres;unordered_map>m;for(autoa:tickets){m[a.first].insert(a.second);}dfs(m,"JFK",res);retur
LandscapeMi
·
2020-09-15 05:39
leetcode(c++)
Leetcode_c++
: Search a 2D Matrix (074)
题目Writeanefficientalgorithmthatsearchesforavalueinanmxnmatrix.Thismatrixhasthefollowingproperties:Integersineachrowaresortedfromlefttoright.Thefirstintegerofeachrowisgreaterthanthelastintegeroftheprev
LandscapeMi
·
2020-08-11 22:20
leetcode(c++)
leetcode_c++
:图:Clone Graph(133)
Cloneanundirectedgraph.Eachnodeinthegraphcontainsalabelandalistofitsneighbors.OJ’sundirectedgraphserialization:Nodesarelabeleduniquely.Weuse#asaseparatorforeachnode,and,asaseparatorfornodelabelandeach
LandscapeMi
·
2020-08-10 18:54
leetcode(c++)
leetcode_c++
:Restore IP Addresses(091)
Givenastringcontainingonlydigits,restoreitbyreturningallpossiblevalidIPaddresscombinations.Forexample:Given“25525511135”,return[“255.255.11.135”,“255.255.111.35”].(Orderdoesnotmatter)回溯classSolution{p
LandscapeMi
·
2020-08-10 18:53
leetcode(c++)
leetcode_c++
:哈希: Copy List with Random Pointer(138)
Alinkedlistisgivensuchthateachnodecontainsanadditionalrandompointerwhichcouldpointtoanynodeinthelistornull.Returnadeepcopyofthelist.算法O(N)/**程序用来复制一个复杂链表*复杂链表表示:存在2个指针,一个指针之后下一个节点,另外一个随机指针指向随机节点*分成3步:
LandscapeMi
·
2020-08-10 18:53
leetcode(c++)
leetcode_c++
刷题_001_两数之和_easy
题目描述:给定一个整数数组nums和一个目标值target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。示例:给定nums=[2,7,11,15],target=9因为nums[0]+nums[1]=2+7=9所以返回[0,1]解法:1,暴力搜索,两个for循环搞定,时间复杂度O(n2)O(n^2)O(n2
xiaotao_1
·
2020-07-12 16:39
leetcode
leetcode_c++
刷题_005_最长回文子串_mid_动态规划_字符串
题目描述:给定一个字符串s,找到s中最长的回文子串。你可以假设s的最大长度为1000。注:回文是指正着读和反着读都一样示例1:输入:"babad"输出:"bab"注意:"aba"也是一个有效答案。示例2:输入:"cbbd"输出:"bb"解析:用动态规划进行回文判断,代码如下:classSolution{public:stringlongestPalindrome(strings){intn=s.s
xiaotao_1
·
2020-07-12 16:39
leetcode
leetcode_c++
刷题_003_无重复字符的最长子串_mid_字符串_滑动窗口_hash表
给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。示例1:输入:"abcabcbb"输出:3解释:因为无重复字符的最长子串是"abc",所以其长度为3。示例2:输入:"bbbbb"输出:1解释:因为无重复字符的最长子串是"b",所以其长度为1。示例3:输入:"pwwkew"输出:3解释:因为无重复字符的最长子串是"wke",所以其长度为3。请注意,你的答案必须是子串的长度,"pwke"是
xiaotao_1
·
2020-07-12 16:39
leetcode
leetcode_c++
刷题_002_两数相加_mid
题目描述:给出两个非空的链表用来表示两个非负的整数。其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只能存储一位数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。您可以假设除了数字0之外,这两个数都不会以0开头。示例:输入:(2->4->3)+(5->6->4)输出:7->0->8原因:342+465=807思路:链表的数储存是倒序的,因此只要从链表头相加,再将
xiaotao_1
·
2020-07-12 16:39
leetcode
leetcode_c++
刷题_004_寻找两个正序数组的中位数_hard_二分查找_数组
题目描述:给定两个大小为m和n的正序(从小到大)数组nums1和nums2。请你找出这两个正序数组的中位数,并且要求算法的时间复杂度为O(log(m+n))。你可以假设nums1和nums2不会同时为空。示例1:nums1=[1,3]nums2=[2]则中位数是2.0示例2:nums1=[1,2]nums2=[3,4]则中位数是(2+3)/2=2.5思路:毕竟是hard难度的题,实在是太难了。先记
xiaotao_1
·
2020-07-12 16:39
leetcode
leetcode
c++
二分查找
数组
中位数
leetcode_c++
:链表:add two numbers(002)
*#include#include#include#include#include#includeusingnamespacestd;structListNode{intval;ListNode*next;ListNode(intx):val(x),next(NULL){}};//尾插法ListNode*addValAndCreateNewNode(ListNode*cur,intval){cur
LandscapeMi
·
2020-07-07 17:18
leetcode(c++)
leetcode_c++
:链表:Reorder List(143)
GivenasinglylinkedlistL:L0→L1→…→Ln-1→Ln,reorderitto:L0→Ln→L1→Ln-1→L2→Ln-2→…Youmustdothisin-placewithoutalteringthenodes’values.Forexample,Given{1,2,3,4},reorderitto{1,4,2,3}.利用快慢两个指针将链表一分为二,针对第二个子链表求倒
LandscapeMi
·
2020-06-24 14:08
leetcode(c++)
leetcode_c++
:Search for a Range(034)
题目Givenasortedarrayofintegers,findthestartingandendingpositionofagiventargetvalue.Youralgorithm’sruntimecomplexitymustbeintheorderofO(logn).Ifthetargetisnotfoundinthearray,return[-1,-1].Forexample,Giv
LandscapeMi
·
2020-06-24 14:08
leetcode(c++)
leetcode_c++
:哈希:intersection of Two Arrays(349)
Giventwoarrays,writeafunctiontocomputetheirintersection.Example:Givennums1=[1,2,2,1],nums2=[2,2],return[2].求两个数组的交集,元素不能重复。算法setclassSolution{public:vectorintersection(vector&nums1,vector&nums2){sets1
LandscapeMi
·
2020-06-24 14:08
leetcode(c++)
leetcode_c++
:Missing Number(268)
题目Givenanarraycontainingndistinctnumberstakenfrom0,1,2,…,n,findtheonethatismissingfromthearray.Forexample,Givennums=[0,1,3]return2.Note:Youralgorithmshouldruninlinearruntimecomplexity.Couldyouimplemen
LandscapeMi
·
2016-06-19 12:34
leetcode(c++)
leetcode_c++
:Next Permutation (031)
题目Implementnextpermutation,whichrearrangesnumbersintothelexicographicallynextgreaterpermutationofnumbers.Ifsucharrangementisnotpossible,itmustrearrangeitasthelowestpossibleorder(ie,sortedinascendingor
mijian1207mijian
·
2016-05-13 00:00
leetcode_c++
:Remove Element (027)
题目Givenanarrayandavalue,removeallinstancesofthatvalueinplaceandreturnthenewlength.Donotallocateextraspaceforanotherarray,youmustdothisinplacewithconstantmemory.Theorderofelementscanbechanged.Itdoesn’t
mijian1207mijian
·
2016-05-13 00:00
leetcode_c++
:Remove Duplicates from Sorted Array(026)
题目Givenasortedarray,removetheduplicatesinplacesuchthateachelementappearonlyonceandreturnthenewlength.Donotallocateextraspaceforanotherarray,youmustdothisinplacewithconstantmemory.Forexample,Giveninput
mijian1207mijian
·
2016-05-11 23:00
leetcode_c++
:4sum(016)
GivenanarraySofnintegers,arethereelementsa,b,c,anddinSsuchthata+b+c+d=target?Findalluniquequadrupletsinthearraywhichgivesthesumoftarget.Note:Elementsinaquadruplet(a,b,c,d)mustbeinnon-descendingorder.(
mijian1207mijian
·
2016-05-11 14:00
leetcode_c++
:3Sum Closest(016)
题目GivenanarraySofnintegers,findthreeintegersinSsuchthatthesumisclosesttoagivennumber,target.Returnthesumofthethreeintegers.Youmayassumethateachinputwouldhaveexactlyonesolution.Forexample,givenarrayS={
mijian1207mijian
·
2016-05-09 22:00
leetcode_c++
:3Sum(015)
题目GivenanarraySofnintegers,arethereelementsa,b,cinSsuchthata+b+c=0?Findalluniquetripletsinthearraywhichgivesthesumofzero.Note:Elementsinatriplet(a,b,c)mustbeinnon-descendingorder.(ie,a≤b≤c)Thesolution
mijian1207mijian
·
2016-05-09 21:00
leetcode_c++
:Median_of _two_sorted_arrays(004)
题目两个已经排序好的数组num1和num2,长度分别是m和n。找到两个有序数组的中位数(中间的那个数,若为偶数,则是中间的两个数的平均数)要求复杂度是O(lg(n+m))算法1Merge两个数组,然后取得中位数复杂度:O(n+m)#include #include #include usingnamespacestd; constintmaxn=100; classSolution{ publ
mijian1207mijian
·
2016-05-06 00:00
上一页
1
下一页
按字母分类:
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
其他