![](https://img-blog.csdnimg.cn/20201103180137328.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode
leetcode题目
路上的追梦人
尽人事,听天命
展开
-
百度笔试- 序列合并
描述其中系数aj都是整数满足0≤aj≤1000且至少有两个系数严格大于0,分别将n=1,n=2,n=3n...代入以上函数可以得到一个无穷长度的整数序列,即用8个系数a7,a6...a0可以唯一确定一个无穷长度的整数序列,现在给出k个通过以上方法定义的无穷序列,你需要求出将这些序列所有数字放在一起后,第n小的数字是多少?输入描述:第一行包含一个整数k,1≤k≤104接下来k行,每行包含8个整数a7,a6,.....a0,表示一个函数的系数,0≤aj≤1000最后一行包含一个整数n,1原创 2021-08-13 11:40:05 · 122 阅读 · 0 评论 -
美团笔试-病毒传播
linux惊群效应详细的介绍什么是惊群,惊群在线程和进程中的具体表现,惊群的系统消耗和惊群的处理方法。1、惊群效应是什么? 惊群效应也有人叫做雷鸣群体效应,不过叫什么,简言之,惊群现象就是多进程(多线程)在同时阻塞等待同一个事件的时候(休眠状态),如果等待的这个事件发生,那么他就会唤醒等待的所有进程(或者线程),但是最终却只可能有一个进程(线程)获得这个时间的“控制权”,对该事件进行处理,而其他进程(线程)获取“控制权”失败,只能重新进入休眠状态,这种现象和性能浪费就叫做惊群。 ...原创 2021-07-13 21:25:24 · 182 阅读 · 2 评论 -
剑指Offer-连续子数组的最大和
输入一个整型数组,数组中的一个或连续多个整数组成一个子数组。求所有子数组的和的最大值。要求时间复杂度为O(n)。示例1:输入: nums = [-2,1,-3,4,-1,2,1,-5,4]输出: 6解释:连续子数组[4,-1,2,1] 的和最大,为6。本文选用分治法的思想解题,其实可以使用动态规划的。分而治之分治算法的解题思路:先将问题分解为子问题;解决子问题后,再将子问题合并,解决主要问题。使用分治法解此题:将数组分为2部分。例如[1,2,3,4]被分为[1,2]...原创 2021-04-29 15:28:35 · 134 阅读 · 0 评论 -
LeetCode-强盗团伙
19201920年的芝加哥,出现了一群强盗。如果两个强盗遇上了,那么他们要么是朋友,要么是敌人。而且有一点是肯定的,就是:我朋友的朋友是我的朋友;我敌人的敌人也是我的朋友。两个强盗是同一团伙的条件是当且仅当他们是朋友。现在给你一些关于强盗们的信息,问你最多有多少个强盗团伙。输入格式第一行包含整数NN,表示强盗的个数(从11编号到NN)。第二行包含整数MM,表示关于强盗的信息条数。接下来MM行,每行可能是F p q或是E p q,FF表示pp和qq...原创 2021-04-24 17:24:24 · 247 阅读 · 0 评论 -
腾讯笔试-出现次数TopK问题
题目描述给定String类型的数组strArr,再给定整数k,请严格按照排名顺序打印 出次数前k名的字符串。[要求]如果strArr长度为N,时间复杂度请达到O(N \log K)O(NlogK)输出K行,每行有一个字符串和一个整数(字符串表示)。你需要按照出现出现次数由大到小输出,若出现次数相同时字符串字典序较小的优先输出示例1输入["1","2","3","4"],2返回值[["1","1"],["2","1"]]示例2输入["1","1"..原创 2021-04-20 15:58:28 · 254 阅读 · 0 评论 -
华为机考-Redraiment的走法
题目描述Redraiment是走梅花桩的高手。Redraiment可以选择任意一个起点,从前到后,但只能从低处往高处的桩子走。他希望走的步数最多,你能替Redraiment研究他最多走的步数吗?本题含有多组样例输入输入描述:输入多行,先输入数组的个数,再输入相应个数的整数输出描述:输出结果示例1输入62 5 1 5 4 5 33 2 1输出31说明6个点的高度各为 2 5 1 5 4 5如从第1格开始走,最多为3步,...原创 2021-04-20 09:42:25 · 569 阅读 · 0 评论 -
华为机试-四则运算
题目描述输入一个表达式(用字符串表示),求这个表达式的值。保证字符串中的有效字符包括[‘0’-‘9’],‘+’,‘-’,‘*’,‘/’,‘(’,‘)’,‘[’,‘]’,‘{’,‘}’。且表达式一定合法。输入描述:输入一个算术表达式输出描述:得到计算结果示例1输入3+2*{1+2*[-4/(8-6)+7]}输出25利用两个stack,一个存储计算结果的值,一个存储符号,留意的地方是计算结果的值需要考虑正负号#include ...原创 2021-04-19 21:27:06 · 541 阅读 · 0 评论 -
LeetCode:华为机考-森林中的兔子
/**** 森林中的兔子* 森林中,每个兔子都有颜色.其中一些兔子(可能是全部)告诉你还有多少其他的兔子和自己有相同的颜色.* 我们将这些回答放在answers数组里.* 返回森林中兔子的最少数量.***/#include <iostream>#include <vector>#include <map>#include <unordered_map>#include <algorithm>u...原创 2021-04-04 14:48:23 · 269 阅读 · 0 评论 -
LeetCode:国王的烦恼之居民抗议的天数
问题描述 C国由n个小岛组成,为了方便小岛之间联络,C国在小岛间建立了m座大桥,每座大桥连接两座小岛。两个小岛间可能存在多座桥连接。然而,由于海水冲刷,有一些大桥面临着不能使用的危险。 如果两个小岛间的所有大桥都不能使用,则这两座小岛就不能直接到达了。然而,只要这两座小岛的居民能通过其他的桥或者其他的小岛互相到达,他们就会安然无事。但是,如果前一天两个小岛之间还有方法可以到达,后一天却不能到达了,居民们就会一起抗议。 现在C国的国王已经知道了每座桥能使用的天数,超过这个天数就不能使用了。.原创 2021-03-04 16:17:58 · 159 阅读 · 1 评论 -
LeetCode:任务调度所需要的最少时间
Given a char array representing tasks CPU need to do.It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order.Each task could be done in one interval.For each interval,CPU could fi.原创 2021-03-03 22:14:11 · 2606 阅读 · 1 评论 -
LeetCode:求三个元素等于零的所有组合
Given an array nums of n integers,are there elements a,b,c in nums such that a+b+c=0?Find all unique triplets in the array which gives the sum of zero.Notice that the solution set must not contain duplicate triplets.Example 1:Input: nums=[-1,0,1,2,-.原创 2021-03-03 11:03:59 · 368 阅读 · 0 评论 -
LeetCode:判断是否为扑克牌的顺子
从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的.2~10为数字本身.A为1,J为11,Q为12,K为13,而大、小王为0,可以看成任意数字.A不能视为14.解题思路:此题需要注意大小王的个数可能为5,因为没限制扑克牌的副数.方法1:set+遍历(1)遍历5张牌,若遇到num[i]为0的牌,直接continue;(2)利用两个变量Max,Min分别统计数组中的最大值和最小值;(3)考虑到数组中可能存在非零的重复元素,根据insert的返回值,可以判断是否出现重复的元素.原创 2021-03-02 12:58:04 · 493 阅读 · 1 评论 -
LeetCode:对花园进行种花
You have n gardens,labeled from 1 to n,and an array paths where paths[i]=[xi,yi] describes a biddirectional path between garden xi to garden yi.In each garden,you want to plant one of 4types of flowers.All gardens have at most 3 paths coming into or le.原创 2021-03-02 11:09:23 · 618 阅读 · 0 评论 -
LeetCode:求字符串数组中字符串乘积最大值
Given a string array words,find the maximum value of length(word[i])*length(word[j]),where the two words do not share common letters.You may assume that each word will contain only lower case letters.If no such two words exist,return 0.Example 1:Inpu.原创 2021-03-01 12:26:26 · 514 阅读 · 0 评论 -
LeetCode:合并k个有序的链表
You are given an array of k linked-lists,each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it.Example 1:Input: lists = [[1,4,5],[1,3,4],[2,6]]Output: [1,1,2,3,4,4,5,6]Explanation: The lin.原创 2021-02-28 18:19:34 · 237 阅读 · 0 评论 -
LeetCode:合并两个有序的链表
/*方法1:迭代法利用两个指针分别指向两个链表的头部,然后逐次进行比较,并满足条件的进行+1即可.最后再链接没有遍历完的链表即可.时间复杂度为:O(n),空间复杂度为O(1).方法2:递归*/#include <iostream>using namespace std;struct LinkNode{ int val; LinkNode* next; LinkNode():val(0),next(nullptr){} LinkNode.原创 2021-02-28 18:18:05 · 106 阅读 · 0 评论 -
LeetCode:实现最大堆
优先队列(priority queue)可以在O(1)时间内获取最大值,并且在0(logn)时间内取出最大值或插入任意值.优先队列常常用堆(heap)来实现,堆是一个完全二叉树,其每个节点的值总是大于等于或小于等于子节点的值.实际实现堆时,通常用一个数组而不是指针建立一盒树.这是因为堆是完全二叉树,所以利用数组表示时,(1)若根节点的位置为0,则位置i的节点的父节点一定为(i-1)/2,而它的两个字节点的位置一定为2i+1和2i+2.(2)若根节点的位置为1,则位置i的节点的父节点一定为i/2,而.原创 2021-02-26 23:28:03 · 526 阅读 · 0 评论 -
leetcode:求这两个连续子数组元素最大之和为多少
Given an array A of non-negative integers,return the maximum sum of elements in two non-overlapping(contiguous)subarrays,which have lengths L and M.(For clarification,the L-length subarrays could occur before or after the M-length subarrays.)Formally,r.原创 2021-02-23 23:38:44 · 256 阅读 · 0 评论 -
LeetCode:判断查询过的小写字母按照先后顺序进行拼接能否在字符串数组中找到
Implement the StreamChecker class as follows:(1)StreamChecker(words):Constructor,init the data structure with the given words.(2)query(letter):returns true if and only for some k>=1,the last k characters queried(in order from oldest to newest,includ.原创 2021-02-23 17:00:40 · 167 阅读 · 0 评论 -
LeetCode:求最多能连接多少根线,而且不会发生相交.
We write the integers of A and B (in the order they are given) on two separate horizontal lines.Now,we may draw connecting lines:a straight line connecting two numbers A[i] and B[i] such that: (1)A[i]==B[i]; (2)The line we draw does not intersect any .原创 2021-02-22 20:01:50 · 475 阅读 · 0 评论 -
实现桶排序算法
Java语言实现定义节点package bucketSort;public class LinkedNode { public int value; public LinkedNode next; public LinkedNode(int value){this.value=value;}}桶排序package bucketSort;import java.util.Arrays;public class BucketSort { .原创 2021-02-22 00:02:30 · 136 阅读 · 0 评论 -
LeetCode:执行的最小和最大移动次数
Three stones are on a number line at position a,b,and c.Each turn,you pick up stone atan endpoint (ie.,either the lowest or highest position stone),and move it to an unoccupied position between those endpoints.Formally,let's say the stones are curren..原创 2021-02-21 17:30:37 · 427 阅读 · 0 评论 -
LeetCode:判断能否将这个数组分割成两个子集,使得两个子集的元素之和相等
Given a non-empty array containing only positive integers,find if the array can be partitioned to two subsets such that the sum of elements in both subsets is equal.Note:1.Each of the array element will not exceed 100.2.The array size will not exceed.原创 2021-02-19 21:13:27 · 1671 阅读 · 0 评论 -
LeetCode:返回待查询项与给定模式串匹配的bool数组
A query word matches a given pattern if we can insert lowercase letters to the pattern wordso that it equals the query.(We may insert each character at any position,and may insert 0 characters.)Given a list of queries,and a pattern,return an answer lis.原创 2021-02-19 18:24:07 · 261 阅读 · 0 评论 -
LeetCode:找到该数组中和为k的连续的子数组的个数
Given an array of integers nums and an integer k,return the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums=[1,1,1],k=2Output:2Example 2:Input:nums=[1,2,3],k=3Output:2Example 3:Input:nums=[1,-1,0],k=0Output:3...原创 2021-02-17 20:24:33 · 1742 阅读 · 0 评论 -
LeetCode:返回可以使得数组的和等于目标数S的所有添加符号的方法数
You are given a list of non-negative integers,a1,a2,...,an,and a target,S.Now you have 2 symbols + and -.For each integer,you should choose one from + and - as its new symbol.Find out how many ways to assign symbols to make sum of integers equal to targ.原创 2021-02-17 10:47:17 · 381 阅读 · 0 评论 -
LeetCode:返回将每个人都飞到某城市的最低费用
A company is planning to inerview 2n people.Given the array costs where costs[i]=[aCosti,bCosti],the cost of flying the ith person to city a isaCosti,and the cost of flying the ith person to city b is bCosti.Return the minimum cost of fly every person .原创 2021-02-16 18:01:33 · 338 阅读 · 0 评论 -
LeetCode:求最长的等差数列长度
Given an array A of integers,return the length of the longest arithmetic subsequence in A.Recall that a subsequence of A is a list A[i_1], A[i_2]....,A[i_k] with 0<=i_1<i_2...<i_k=A.length-1,and that a sequence B is arithmetic if B[i+1]-B[i] ar.原创 2021-02-15 21:26:45 · 403 阅读 · 0 评论 -
LeetCode:最小的视频片段拼接数目
You are given a series of video clips from a sporting event that lasted T seconds.These videoclips can be overlapping with each other and have varied lengths.Each video clip clips[i] is an interval:it starts at time clips[i][0] and ends at timeclips[i].原创 2021-02-14 11:58:32 · 159 阅读 · 0 评论 -
LeetCode:以字符串的形式返回n的最小的好进制
For an integer n,we call k>=2 a good base of n ,if all digits of n base k are 1.Now given a string representing n,you should return the smallest good base of n in string format.Example 1:Input:"13"Output:"3"Explanation:13 base 3 is 111.Example.原创 2021-02-13 11:36:59 · 133 阅读 · 0 评论 -
LeetCode:求移除石子的最大得分
You are playing a solitaire game with three piles of stones sizes a,b, and c respectively.Each turn you chooose two different non-empty piles,take one stone from each,and add 1 pointto your score.The game stops when there are few than two-empty piles(me.原创 2021-02-12 22:48:46 · 280 阅读 · 0 评论 -
LeetCode:过滤餐馆
Given the array restaurants where restaurants[i]=[id,rating,veganFriendly,price,distance].You have to filter the restaurants using three filters.The veganFriendly filter will be either true(meaning you should only include restaurant).Inaddition,you hav.原创 2021-02-09 20:24:32 · 140 阅读 · 0 评论 -
LeetCode:找出并返回可以覆盖所有房屋的最小加热半径.
Winter is coming!Your first job during the contest is to design a standard heater with fixed warmall the houses.Now,you are given positions of houses and heaters on a horizontal line,find out a minimum radius of heaters so that all houses could be cove.原创 2021-02-09 11:34:32 · 387 阅读 · 0 评论 -
LeetCode:找出每个节点值的下一个较大的节点值
We are given a linked with head as the first node.Let's number the nodes int the list: node_1,node_2,node_3,...etc.Each node may have a next larger value:for node_i,next_larger(node_i) is the node_j.val,and j is the smallest possible choice.If such a j.原创 2021-02-08 17:44:36 · 144 阅读 · 0 评论 -
LeetCode:One-Zero找出并返回strs的最大子集的大小
DescriptionIn the computer world,use restricted resource you have to generate maximum benefit is what we alwayswant to pursue.For now,suppose you are a dominator of m 0s and n 1s respectively.On the other hand,there is an arraywith strings consistin.原创 2021-02-07 22:28:52 · 311 阅读 · 0 评论 -
LeetCode:计算研究者的h指数
题目Given an array of citations(each citation is a non-negative integer) of a research,write a function to compute the research's h-index.According to the definition of h-index on Wikipedia:"A scientist has index h if h of his/her Npapers have at leas.原创 2021-02-07 12:14:47 · 385 阅读 · 0 评论 -
LeetCode:判断一个数字是否为丑陋数字
Write a program to check whether a given number is an ugly number.Ugly numbers are positive number whose prime factors only include 2,3,5.Number '1' is typically treated as an ugly number.Example 1:Input:6Output:trueExplanation:6=2x3Example 2:In.原创 2021-02-06 23:33:58 · 190 阅读 · 0 评论 -
LeetCode:判断字符串s和t是否为同字母异序
Given two strings and t,write a function to determine if it is an anagram of s.Example 1:Input:s="anagram",t="nagaram"Output:trueExample 2:Input:s="rat",t="car"Output:falseFollow up:What if the inputs contain unicode characters?How would you ad.原创 2021-02-06 22:50:03 · 206 阅读 · 0 评论 -
LeetCode:判断str字符串是否遵循模板字符串
Given a pattern and a string str,find if str follows the same pattern.Here follow means a full match,such that there is a bijection a letter in pattern and a non-tmpty word in str.Examples:pattern = "abba", str = "dog cat cat dog" should return true.原创 2021-02-05 23:50:27 · 392 阅读 · 0 评论 -
LeetCode:求如何翻转可以使得数组有序
Given an array of integers arr,sort the array by performing a seriers of pancake flips. In one pancake flip we do the following steps:(1)choose an integer k where 1<=k<=arr.length.(2)Reverse the sub-array arr[1...k].For example,if arr=[3,2,1,4] .原创 2021-02-04 20:13:10 · 458 阅读 · 0 评论