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
lintCode
LintCode
-365.二进制中有多少个1
题目描述计算在一个32位的整数的二进制表式中有多少个1.样例给定32(100000),返回1给定5(101),返回2给定1023(111111111),返回9解答思路1这个题目用java的内建函数很简单,但是它作为OJ题这肯定不是本意。代码1publicclassSolution{/***@paramnum:aninteger*@return:aninteger,thenumberofonesin
悠扬前奏
·
2020-03-22 16:58
LintCode
不同的路径
一:有一个机器人的位于一个M×N个网格左上角(下图中标记为'Start')。机器人每一时刻只能向下或者向右移动一步。机器人试图达到网格的右下角(下图中标记为'Finish')。问有多少条不同的路径?1,11,21,31,41,51,61,72,13,13,7publicclassSolution{/***@paramn,m:positiveinteger(1<=n,m<=100)*@returna
Arnold134777
·
2020-03-22 06:26
lintcode
计算数字k在0到n中的出现的次数,k可能是0~9的一个值
当k不为0时从1至10,在它们的个位数中,任意k都出现了1次。从1至100,在它们的十位数中,任意k都出现了10次。从1至1000,在它们的百位数中,任意k都出现了100次。依次类推,从1至10的i次幂,在它们的左数第二位中,任意k都出现了10的i-1次幂次。举个例子,n=2593,k=5,从1至2593中,数字5总计出现了813次,其中有259次出现在个位,260次出现在十位,294次出现在百位
yzawyx0220
·
2020-03-22 05:16
LintCode
最大正方形
题目在一个二维01矩阵中找到全为1的最大正方形样例10100101111111110010返回4分析动态规划dp[i][j]:最大正方形的边长状态转移方程:if(matrix[i][j]==1){dp[i][j]=Math.min(dp[i-1][j-1],Math.min(dp[i-1][j],dp[i][j-1]))+1;}elsedp[i][j]=0;代码publicclassSolutio
六尺帐篷
·
2020-03-22 04:08
Lintcode
29 Interleaving String solution 题解
【题目链接】http://www.
lintcode
.com/en/problem/interleaving-string/【题目解析】dp[i][j]表示s1前
代码码着玩
·
2020-03-22 01:26
LintCode
奇偶分割数组
题目分割一个整数数组,使得奇数在前偶数在后。样例给定[1,2,3,4],返回[1,3,2,4]。分析这道题其实很熟悉。将奇数排在前,偶数排在后是不是和快速排序中的partiton算法很类似。其实是类似的。设置两个指针,一头一尾,分别寻找偶数和奇数代码publicclassSolution{/***@paramnums:anarrayofintegers*@return:nothing*/publi
六尺帐篷
·
2020-03-22 00:58
蚂蚁金服面试经历(内含大量干货)
当日设了七点闹钟,结果五点五十三分惊醒后再无法入睡,起床,重新翻看之前做的笔记和重点,在
lintcode
上找了几道可能性较大的题进行练手。10点准时在蚂蚁金服总部开始面试,十点四十七分结束。
Sunsyne_f67f
·
2020-03-21 17:53
Interview Question - Six Degrees
Question:https://aaronice.gitbooks.io/
lintcode
/content/graph_search/six_degrees.htmlMycode:publicintsixDegrees
Richardo92
·
2020-03-21 17:54
LintCode
N皇后问题
题目n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击。给定一个整数n,返回所有不同的n皇后问题的解决方案。每个解决方案包含一个明确的n皇后放置布局,其中“Q”和“.”分别表示一个女王和一个空位置。样例对于4皇后问题存在两种解决的方案:[".Q..",//Solution1"...Q","Q...","..Q."],["..Q.",//Solution2"Q...","...Q"
六尺帐篷
·
2020-03-21 16:30
Graph Valid Tree(图是否是树)
http://www.
lintcode
.com/zh-cn/problem/graph-valid-tree/importjava.util.HashMap;importjava.util.HashSet
天街孤独
·
2020-03-21 10:44
lintcode
-二叉树中的最大路径和
给出一棵二叉树,寻找一条路径使其路径和最大,路径可以在任一节点中开始和结束(路径和为两个节点之间所在路径上的节点权值之和)最大路径一定是以某节点为根,加上左右子树中的最大路径和/***DefinitionofTreeNode:*classTreeNode{*public:*intval;*TreeNode*left,*right;*TreeNode(intval){*this->val=val;*
鬼谷神奇
·
2020-03-21 09:14
LintCode
- 二叉树的锯齿形层次遍历(中等)
版权声明:本文为博主原创文章,未经博主允许不得转载。难度:中等要求:给出一棵二叉树,返回其节点值的锯齿形层次遍历(先从左往右,下一层再从右往左,层与层之间交替进行)样例:给出一棵二叉树{3,9,20,#,#,15,7},3/\920/\157返回其锯齿形的层次遍历为:[[3],[20,9],[15,7]]实现:/***DefinitionofTreeNode:*publicclassTreeNod
柒黍
·
2020-03-21 07:58
Segment Tree Build II(线段树的构造 II)
http://www.
lintcode
.com/en/problem/segment-tree-build-ii/请参阅SegmentTreeModify(线段树的修改)一定要注意最后对max进行赋值。
天街孤独
·
2020-03-21 05:55
js刷林扣
lintcode
(2017年3月)
3.1069.给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问)二叉树的层次遍历样例给一棵二叉树{3,9,20,#,#,15,7}:3/\920/\157返回他的分层遍历结果:[[3],[9,20],[15,7]]functionlevelOrder(arr){varres=[]vartempArr=[]varlevelNum=1//每层的节点数varlevelTotal=1//层的阶乘f
mytac
·
2020-03-21 02:45
LintCode
-373.奇偶分割数组
题目描述分割一个整数数组,使得奇数在前偶数在后。样例给定[1,2,3,4],返回[1,3,2,4]。解答思路从前往后找到的偶数,与从后往前找到的奇数换位子,两个游标相遇表示替换完毕。代码publicclassSolution{/***@paramnums:anarrayofintegers*@return:nothing*/publicvoidpartitionArray(int[]nums){/
悠扬前奏
·
2020-03-20 19:28
Segment Tree Query(线段树的查询)
http://www.
lintcode
.com/zh-cn/problem/segment-tree-query/请先参阅SegmentTreeBuild(线段树的构造)来理解一下线段树。
天街孤独
·
2020-03-20 18:04
LintCode
合并排序数组 II
题目合并两个排序的整数数组A和B变成一个新的数组。注意事项你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素。样例给出A=[1,2,3,empty,empty],B=[4,5]合并之后A将变成[1,2,3,4,5]代码classSolution{/***@paramA:sortedintegerarrayAwhichhasmelements,*butsizeofAism+n
六尺帐篷
·
2020-03-20 14:09
LintCode
- 链表划分(普通)
版权声明:本文为博主原创文章,未经博主允许不得转载。难度:容易要求:给定一个单链表和数值x,划分链表使得所有小于x的节点排在大于等于x的节点之前。你应该保留两部分内链表节点原有的相对顺序。样例给定链表1->4->3->2->5->2->null,并且x=3返回**1->2->2->4->3->5->null**思路:多指针偏移/***@paramhead:Thefirstnodeoflinkedl
柒黍
·
2020-03-20 08:48
LintCode
136. Palindrome Partitioning
原题
LintCode
136.PalindromePartitioningDescriptionGivenastrings,partitionssuchthateverysubstringofthepartitionisapalindrome.Returnallpossiblepalindromepartitioningofs.ExampleGivens
Andiedie
·
2020-03-20 07:31
lintcode
搜索旋转排序数组
六十二:http://www.
lintcode
.com/zh-cn/p
yzawyx0220
·
2020-03-20 07:37
LintCode
最后一个单词的长度
题目给定一个字符串,包含大小写字母、空格'',请返回其最后一个单词的长度。如果不存在最后一个单词,请返回0。样例给定s="HelloWorld",返回5。分析两种方法,一个顺着找,一个倒着找。代码publicclassSolution{/***@paramsAstring*@returnthelengthoflastword*/publicintlengthOfLastWord(Strings){
六尺帐篷
·
2020-03-20 05:35
Insert Delete GetRandom O(1)
http://www.
lintcode
.com/en/problem/insert-delete-getrandom-o1/因为要求是o1,所以使用Map来存储。
天街孤独
·
2020-03-20 03:01
Lintcode
141 Sqrtx solution 题解
【题目链接】www.
lintcode
.com/en/problem/sqrtx/【题目解析】问题可以转化为从1~x寻找目标数字,于是二分法就可以提供O(log(n))的时间复杂度,O(1)的空间复杂度。
程风破浪会有时
·
2020-03-20 02:31
LintCode
- 二叉树的层次遍历 II(中等)
版权声明:本文为博主原创文章,未经博主允许不得转载。难度:中等要求:给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历)样例:一个例子:给出一棵二叉树{3,9,20,#,#,15,7},3/\920/\157按照从下往上的层次遍历为:[[15,7],[9,20],[3]]实现:/***DefinitionofTreeNode:*public
柒黍
·
2020-03-20 01:31
LintCode
-82.落单的数
题目描述给出2*n+1个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。样例给出[1,2,2,1,3,4,3],返回4解答思路按数取异或,相同会等于0,最后等于不同的数。代码publicclassSolution{/***@paramA:anintegerarray*return:ainteger*/publicintsingleNumber(int[]A){//Writeyour
悠扬前奏
·
2020-03-19 20:25
Count Primes
https://www.
lintcode
.com/problem/count-primes/descriptionpublicclassSolution{/***@paramn:ainteger*@return
天街孤独
·
2020-03-19 14:33
LintCode
连接两个字符串中的不同字符
classResolution:"""给出两个字符串,你需要修改第一个字符串,将所有与第二个字符串中相同的字符删除,并且第二个字符串中不同的字符与第一个字符串的不同字符连接"""defconcatenetedString(self,s1,s2):list1=list(s1)list2=list(s2)sameList=[]#找到相同的字符列表forcinlist1:iflist2.count(c)
少年Amore
·
2020-03-19 11:42
刷
Lintcode
,乱序字符(1)
这是一道中等难度的字符串题目。本来按照我的想法,我觉得逻辑上没有问题,但是出在JAVA上的细节问题。虽然,我的逻辑方法自己觉得很生硬。题目给出一个字符串数组S,找到其中所有的乱序字符串(Anagram)。如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中。样例对于字符串数组["lint","intl","inlt","code"]返回["lint","inlt","
2a25936eedd9
·
2020-03-19 09:16
Algorithms ladder IV
problemsets:binarysearch;divideandconquer;
lintcode
97.MaximumDepthofBinaryTree,easy
lintcode
480.BinaryTreePaths
aureole420
·
2020-03-19 07:57
LintCode
6 [Merge Sorted Array II]
原题合并两个排序的整数数组A和B变成一个新的数组。给出A=[1,2,3,4],B=[2,4,5,6],返回[1,2,2,3,4,4,5,6]解题思路不同于[MergeSortedArrayI],由于merge到一个新的数组,所以从前往后,小的出列headA=0headB=0方法二:合并,排序完整代码#方法一classSolution:#@paramAandB:sortedintegerarrayA
Jason_Yuan
·
2020-03-19 05:27
OJ
lintcode
奇偶分割数组
分割一个整数数组,使得奇数在前偶数在后。您在真实的面试中是否遇到过这个题?Yes样例给定[1,2,3,4],返回[1,3,2,4]。classSolution{public:/***@paramnums:avectorofintegers*@return:nothing*/voidpartitionArray(vector&nums){//writeyourcodeherevectorv1;vec
zhaozhengcoder
·
2020-03-19 04:01
LintCode
数组划分
题目给出一个整数数组nums和一个整数k。划分数组(即移动数组nums中的元素),使得:所有小于k的元素移到左边所有大于等于k的元素移到右边返回数组划分的位置,即数组中第一个位置i,满足nums[i]大于等于k。注意事项你应该真正的划分数组nums,而不仅仅只是计算比k小的整数数,如果数组nums中的所有元素都比k小,则返回nums.length。样例给出数组nums=[3,2,2,1]和k=2,
六尺帐篷
·
2020-03-19 04:31
OJ
lintcode
判断字符串是否没有重复字符
实现一个算法确定字符串中的字符是否均唯一出现您在真实的面试中是否遇到过这个题?Yes样例给出"abc",返回true给出"aab",返回falseclassSolution{public:/***@paramstr:astring*@return:aboolean*/boolisUnique(string&str){//writeyourcodeheresetchar_set;for(inti=0
zhaozhengcoder
·
2020-03-19 02:35
LintCode
问题图解-20
本文准备讲解1个算法编程问题,这个算法编程问题来自
LintCode
平台。不了解.
LintCode
平台的读者可以阅读笔者文章(在线编程平台推荐-LeetCode)。
billliu_0d62
·
2020-03-19 01:53
LintCode
- 二叉树的最大深度(普通)
版权声明:本文为博主原创文章,未经博主允许不得转载。难度:容易要求:给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的距离。样例给出一棵如下的二叉树:1/\23/\45这个二叉树的最大深度为3.思路:递归/***DefinitionofTreeNode:*publicclassTreeNode{*publicintval;*publicTreeNodeleft,right;*pu
柒黍
·
2020-03-19 00:41
LintCode
- 两数组的交(普通)
版权声明:本文为博主原创文章,未经博主允许不得转载。难度:容易要求:返回两个数组的交样例nums1=[1,2,2,1],nums2=[2,2],返回[2].思路:/***@paramnums1anintegerarray*@paramnums2anintegerarray*@returnanintegerarray*/publicint[]intersection(int[]nums1,int[]
柒黍
·
2020-03-18 22:44
LintCode
46. Majority Number
原题
LintCode
46.MajorityNumberDescriptionGivenanarrayofintegers,themajoritynumberisthenumberthatoccursmorethanhalfofthesizeofthearray.Findit.NoticeYoumayassumethatthearrayisnon-emptyandthemajoritynumbera
Andiedie
·
2020-03-18 20:32
lintcode
-Segment Tree Query II
/***DefinitionofSegmentTreeNode:*classSegmentTreeNode{*public:*intstart,end,count;*SegmentTreeNode*left,*right;*SegmentTreeNode(intstart,intend,intcount){*this->start=start;*this->end=end;*this->count
鬼谷神奇
·
2020-03-18 17:28
Lintcode
88 Lowest Common Ancestor solution 题解
【题目描述】GiventherootandtwonodesinaBinaryTree.Findthelowestcommonancestor(LCA)ofthetwonodes.Thelowestcommonancestoristhenodewithlargestdepthwhichistheancestorofbothnodes.给定一棵二叉树,找到两个节点的最近公共父节点(LCA)。最近公共祖
程风破浪会有时
·
2020-03-18 16:00
Lintcode
177 Convert Sorted Array to Binary Search Tree With Minimal Height solution 题解
【题目描述】Givenasorted(increasingorder)array,Convertittocreateabinarytreewithminimalheight.【注】Theremayexistmultiplevalidsolutions,returnanyofthem.给一个排序数组(从小到大),将其转换为一棵高度最小的排序二叉树。【注】可能有多有效解存在,返回其中一个即可。【题目链
程风破浪会有时
·
2020-03-18 12:59
lintcode
-单词切分
C++版给出一个字符串s和一个词典,判断字符串s是否可以被空格切分成一个或多个出现在字典中的单词。动态规划的本质:根据已知结论推理未知结论classSolution{public:/***@params:Astrings*@paramdict:Adictionaryofwordsdict*/boolwordBreak(strings,unordered_set&dict){if(s.size()=
鬼谷神奇
·
2020-03-18 11:44
Best Time to Buy and Sell Stock with Transaction Fee
https://www.
lintcode
.com/problem/best-time-to-buy-and-sell-stock-with-transaction-fee/descriptionpublicclassSolution
天街孤独
·
2020-03-18 11:12
Valid Perfect Square
http://www.
lintcode
.com/zh-cn/problem/valid-perfect-square/publicclassSolution{/***@paramnum:apositiveinteger
天街孤独
·
2020-03-18 06:53
LintCode
-181.将整数A转换为B
题目描述如果要将整数A转换为B,需要改变多少个bit位?样例如把31转换为14,需要改变2个bit位。(31)10=(11111)2(14)10=(01110)2解答思路将两个数按位异或统计异或结果中1的个数(网上找的方法,太6了)代码classSolution{/***@parama,b:Twointeger*return:Aninteger*/publicstaticintbitSwapReq
悠扬前奏
·
2020-03-18 02:08
Lintcode
389 Valid Sudoku solution 题解
【题目描述】DeterminewhetheraSudokuisvalid.TheSudokuboardcouldbepartiallyfilled,whereemptycellsarefilledwiththecharacter..Notice:AvalidSudokuboard(partiallyfilled)isnotnecessarilysolvable.Onlythefilledcells
程风破浪会有时
·
2020-03-17 23:28
leetcode每日一题
MergeSortedArrayQuestionleetcode:MergeSortedArray|LeetCodeOJ
lintcode
:(6)MergeSortedArrayGiventwosortedintegerarraysAandB
Sidney001
·
2020-03-17 23:20
Lintcode
58 4Sum solution 题解
【题目描述】GivenanarraySofnintegers,arethereelementsa,b,c,anddinSsuchthata+b+c+d=target?Findalluniquequadrupletsinthearraywhichgivesthesumoftarget.Notice:Elementsinaquadruplet(a,b,c,d)mustbeinnon-descendin
代码码着玩
·
2020-03-17 23:10
LintCode
硬币排成线
有n个硬币排成一条线。两个参赛者轮流从右边依次拿走1或2个硬币,直到没有硬币为止。拿到最后一枚硬币的人获胜。请判定第一个玩家是输还是赢?样例n=1,返回true.n=2,返回true.n=3,返回false.n=4,返回true.n=5,返回true.挑战O(1)时间复杂度且O(1)存储。分析:博弈的思想publicclassSolution{/***@paramn:aninteger*@retu
Arnold134777
·
2020-03-17 22:28
Paint House(房屋染色)
http://www.
lintcode
.com/en/problem/paint-house/?
天街孤独
·
2020-03-17 20:57
LintCode
-6.合并排序数组
题目描述合并两个排序的整数数组A和B变成一个新的数组。样例给出A=[1,2,3,4],B=[2,4,5,6],返回[1,2,2,3,4,4,5,6]解答思路归并排序。建立新的数组,大小为两个数组长度之和。从后往前归并,好处在于,如果大的数组长度足够容纳所有的元素,可以降低空间复杂度。代码classSolution{/***@paramAandB:sortedintegerarrayAandB.*@
悠扬前奏
·
2020-03-17 18:27
上一页
40
41
42
43
44
45
46
47
下一页
按字母分类:
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
其他