当前位置:网站首页>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
边栏推荐
- Différence entre le mode grand et le mode petit
- Alibaba cloud image station supports IPv6!
- R语言使用epiDisplay包的summ函数计算dataframe中指定变量在不同分组变量下的描述性统计汇总信息并可视化有序点图(名称、有效值个数、均值、中位数、标准差、最大值、最小值)
- Picture online collection and delivery system source code
- Go的变量
- STL -- function object
- Modify the configuration of the router connected to your computer. The website is 192.168.1.1
- Advanced Qt development: a preliminary study QT + OpenGL
- Go variables
- 薛定谔的日语学习小程序源码
猜你喜欢

Microsoft Office MSDT代码执行漏洞(CVE-2022-30190)漏洞复现

Microsoft Office MSDT Code Execution Vulnerability (cve-2022-30190) vulnerability recurrence

Use GCC's PGO (profile guided optimization) to optimize the entire system

To understand Devops, you must read these ten books!

Structural requirement analysis of software engineering student information management system

Gerrit+2 triggers Jenkins task

5、Embedding

Some minor problems and solutions encountered when using ubantu

"Upgrade strategy" of two new committers

Recommend 6 open source projects of yyds
随机推荐
D. master router setting and 401 networking
图片在线收款发货系统源码
Li Kou today's question 926 Flip string to monotonic increment
Compilation optimization of performance optimization
Qiushengchang: Practice of oppo commercial data system construction
Go的变量
selenium元素定位
Memory control of node
并发三色标记法
Play kubernetes every 5 minutes summary
Google browser debugging skills
Crazy temporary products: super low price, big scuffle and new hope
Doctor application | National University of Singapore, Xinchao Wang, teacher recruitment, doctor / postdoctoral candidate in the direction of graph neural network
PAT甲级 1142 最大团
How to change Golan back to the English version when it becomes the Chinese version
Google浏览器调试技巧
How to view, modify, and delete SSH
Unit sshd. service could not be found
Selenium element positioning
goland变成中文版了怎么修改回英文版