当前位置:网站首页>Yyds dry goods inventory leetcode question set 911 - 920
Yyds dry goods inventory leetcode question set 911 - 920
2022-06-12 17:16:00 【Brother daze who loves learning】
LeetCode Exercise set
Some questions may be skipped directly , Brush before tidying up leetcode
911. Online elections
Here are two arrays of integers persons and times . In the election , The first i The ticket is for times[i] Vote for the candidate persons[i] Of .
For what happened at the moment t For each query , Need to find out where t The number of the candidate who is always ahead in the election .
stay t The votes cast at any time will also be included in our query . In the case of a draw , The candidate who has recently won the vote will win .
Realization TopVotedCandidate class :
TopVotedCandidate(int[] persons, int[] times)UsepersonsandtimesArray initialization object .int q(int t)According to the rules described above , Return at timetThe number of the leading candidate in the election .
Example :
Tips :
1 <= persons.length <= 5000times.length == persons.length0 <= persons[i] < persons.length0 <= times[i] <= 109timesIs a strictly increasing ordered arraytimes[0] <= t <= 109- Each test case calls at most
104Timeq
912. Sort array
Give you an array of integers nums, Please arrange the array in ascending order .
Example 1:
Example 2:
Tips :
1 <= nums.length <= 5 * 104-5 * 104 <= nums[i] <= 5 * 104
913. Tom and Jerry
The two players play cat and mouse respectively , In one Undirected Play on the map , They take turns .
The form of the graph is :graph[a] It's a list , Satisfied by ab Is all the nodes of an edge in the graph b form .
Mouse from node 1 Start , Be the first to set out ; Cat slave node 2 Start , The second one set out . At the node 0 There is a hole in the .
In every player's action , they must Move along an edge in the graph connected to the current position . for example , If the mouse is at the node 1 , Then it must move to graph[1] Any node in .
Besides , The cat can't move into the hole ( node 0).
then , The game ends in one of the following three situations :
- If the cat and mouse appear at the same node , Cat wins .
- If the mouse reaches the hole , The mouse wins .
- If a position repeats ( namely , The player's position and movement order are the same as the last action ), Game draw .
Here's a picture graph , And assume that both players participate in the game at their best :
- If the mouse wins , Then return to
1; - If the cat wins , Then return to
2; - If there is a draw , Then return to
0.
Example 1:

Example 2:

Tips :
3 <= graph.length <= 501 <= graph[i].length < graph.length0 <= graph[i][j] < graph.lengthgraph[i][j] != igraph[i]Different from each other- The cat and mouse always move in the game
914. Card groups
Give a deck of cards , There is a whole number written on each card .
here , You need to choose a number X, So that we can divide the whole deck into 1 Groups or more :
- In each group
Xcard . - All the cards in the group are written with the same integer .
Only if you choose X >= 2 When to return to true.
Example 1:
Example 2:
Tips :
1 <= deck.length <= 1040 <= deck[i] < 104
915. Split array
Medium difficulty 95 Switch to English to receive dynamic feedback
Given an array nums , Divide it into two consecutive subarrays left and right, bring :
leftEach element in is less than or equal torightEvery element in .leftandrightIt's all non empty .leftThe length of the should be as small as possible .
After completing this grouping, return to left Of length .
Use cases can guarantee the existence of such a partitioning method .
Example 1:
Example 2:
Tips :
2 <= nums.length <= 1050 <= nums[i] <= 106- It can be guaranteed that there is at least one way to deal with
numsdivision .
916. Word subsets
Here are two string arrays words1 and words2.
Now? , If b Every letter in the text appears in a in , Including repeated letters , So it's called string b Is string a Of A subset of .
- for example ,
"wrr"yes"warrior"Subset , But it's not"world"Subset .
If the words2 Every word in b,b All are a Subset , Then we call words1 The words in a yes ** Common words **.
Return... As an array words1 All common words in . You can press In any order Return to the answer .
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Tips :
1 <= words1.length, words2.length <= 1041 <= words1[i].length, words2[i].length <= 10words1[i]andwords2[i]It's only made up of lowercase letterswords1All the strings in Different from each other
917. Just reverse the letters
The difficulty is simple 100 Switch to English to receive dynamic feedback
Given a string S, return “ After reversal ” character string , All characters that are not letters remain in place , And the positions of all letters are reversed .
Example 1:
Example 2:
Example 3:
Tips :
S.length <= 10033 <= S[i].ASCIIcode <= 122SContains no `` or"
918. The maximum sum of the ring subarray
Given a length of n Of Circular integer array nums , return nums Non empty of Subarray Maximum possible and .
Ring array ** It means that the end of the array will be connected with the beginning in a ring . Formally , nums[i] The next element of this is nums[(i + 1) % n] , nums[i] The previous element of is nums[(i - 1 + n) % n] .
Subarray Can only contain fixed buffers at most nums Once for each element in the . Formally , For subarrays nums[i], nums[i + 1], ..., nums[j] , non-existent i <= k1, k2 <= j among k1 % n == k2 % n .
Example 1:
Example 2:
Example 3:
Tips :
n == nums.length1 <= n <= 3 * 104-3 * 104 <= nums[i] <= 3 * 104
919. Complete binary tree inserter
Medium difficulty 60 Switch to English to receive dynamic feedback
Perfect binary tree Every floor ( Except for the last floor ) All completely filled ( namely , The number of nodes reaches the maximum ) Of , And all nodes are concentrated on the left as much as possible .
Design an algorithm , Insert a new node into a complete binary tree , And keep it intact after insertion .
Realization CBTInserter class :
CBTInserter(TreeNode root)Use the header node asrootInitialize the data structure for the given tree ;CBTInserter.insert(int v)Insert a value of... Into the treeNode.val == valThe new nodeTreeNode. Keep the tree in the state of a complete binary tree , And return to the insert nodeTreeNodeThe value of the parent node of ;CBTInserter.get_root()The head node of the tree will be returned .
Example 1:

Tips :
- The number of nodes in the tree ranges from
[1, 1000] 0 <= Node.val <= 5000rootIt's a perfect binary tree0 <= val <= 5000- Each test case calls at most
insertandget_rootoperation104Time
边栏推荐
- Gerrit triggers Jenkins sonarqube scan
- Kill program errors in the cradle with spotbugs
- Doctor application | National University of Singapore, Xinchao Wang, teacher recruitment, doctor / postdoctoral candidate in the direction of graph neural network
- Qiushengchang: Practice of oppo commercial data system construction
- Selenium element positioning
- Schrodinger's Japanese learning applet source code
- 5、Embedding
- Extract the new Chinese cross modal benchmark zero from 5billion pictures and texts, and Qihoo 360's new pre training framework surpasses many SOTAS
- How to view, modify, and delete SSH
- Go的变量
猜你喜欢

selenium元素定位

5、Embedding

Uniapp wallpaper applet source code / double ended wechat Tiktok applet source code

Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134) vulnerability recurrence

Swintransformer network architecture

ShardingJDBC 分库分表详解

Swin transformer code explanation

男神女神投票源码 v5.5.21 投票源码

邱盛昌:OPPO商业化数据体系建设实战

叶子分享站PHP源码下载
随机推荐
Advanced Qt development: a preliminary study QT + OpenGL
D. master router setting and 401 networking
The R language uses the PDF function to save the visual image results to the PDF file, uses the PDF function to open the image device, uses the dev.off function to close the image device, and customiz
Some minor problems and solutions encountered when using ubantu
Sudo of uabntu
Cloud development kunkun chicken music box wechat applet source code
Microsoft Office MSDT Code Execution Vulnerability (cve-2022-30190) vulnerability recurrence
Installation and use of rolabelimg
R语言使用epiDisplay包的tabpct函数生成二维列联表并使用马赛克图可视化列联表(二维列联表、边际频数、以及按行、按列的比例)、自定义设置cex.axis参数改变轴标签数值的大小
Quick start sweep crawler framework
使用ubantu时,遇见的一些小毛病和解决方法
多种Qt的开发方式,你选择哪种?
Gerrit+2触发Jenkins任务
怎么在公司里面做好测试工作(做好测试工作)
反馈式编译
Some introduction to FPC flexible circuit board design
Detailed explanation of shardingjdbc database and table
Making nearly $90billion, Buffett's latest heavy stock exposure
Modify the configuration of the router connected to your computer. The website is 192.168.1.1
有趣的 LD_PRELOAD