当前位置:网站首页>[untitled] Li Kou 496 Next larger element I
[untitled] Li Kou 496 Next larger element I
2022-07-01 03:52:00 【Big drumsticks are best】
nums1 Middle number x Of Next bigger element Refer to x stay nums2 Corresponding position in On the right side Of first Than x Big elements .
Here are two for you There are no repeating elements Array of nums1 and nums2 , Subscript from 0 Start counting , among nums1 yes nums2 Subset .
For each 0 <= i < nums1.length , Find satisfaction nums1[i] == nums2[j] The subscript j , And in nums2 determine nums2[j] Of Next bigger element . If there is no next larger element , Then the answer to this query is -1 .
Returns a length of nums1.length Array of ans As the answer , Satisfy ans[i] As mentioned above Next bigger element .
Example 1:
Input :nums1 = [4,1,2], nums2 = [1,3,4,2].
Output :[-1,3,-1]
explain :nums1 The next larger element of each value in is described below :
- 4 , Mark... In bold and italics ,nums2 = [1,3,4,2]. There is no next bigger element , So the answer is -1 .
- 1 , Mark... In bold and italics ,nums2 = [1,3,4,2]. The next bigger element is 3 .
- 2 , Mark... In bold and italics ,nums2 = [1,3,4,2]. There is no next bigger element , So the answer is -1 .
Example 2:
Input :nums1 = [2,4], nums2 = [1,2,3,4].
Output :[3,-1]
explain :nums1 The next larger element of each value in is described below :
- 2 , Mark... In bold and italics ,nums2 = [1,2,3,4]. The next bigger element is 3 .
- 4 , Mark... In bold and italics ,nums2 = [1,2,3,4]. There is no next bigger element , So the answer is -1 .
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/next-greater-element-i
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
### Their thinking
Here is the solution
### Code
```javascript
/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number[]}
*/
var nextGreaterElement = function(nums1, nums2) {
let a=[],flag=false,flagB=false
for(let i=0;i<nums1.length;i++){
for(let j=0;j<nums2.length;j++){
if(nums1[i]==nums2[j]){
flag=true
continue
}
if(flag&&nums2[j]>nums1[i]){
a.push(nums2[j])
flagB=true
break
}
}
if(!flagB){a.push(-1)}
flagB=false
flag=false
}
return a
};
```
边栏推荐
- 389. 找不同
- [EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
- 【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)
- Appium fundamentals of automated testing - basic principles of appium
- 171. Excel 表列序号
- 整合阿里云短信的问题:无法从静态上下文中引用非静态方法
- Redis(七)优化建议
- Leetcode:829. Sum of continuous integers
- Leetcode: offer 59 - I. maximum value of sliding window
- 4. [WebGIS practice] software operation chapter - data import and processing
猜你喜欢

程序员女友给我做了一个疲劳驾驶检测

Deep learning | rnn/lstm of naturallanguageprocessing
![[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle](/img/94/99090ea91082a385968e071ef3766c.png)
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle

Sort linked list (merge sort)
![[TA frost wolf \u may- hundred people plan] 1.3 secret of texture](/img/dc/ce2819258632cdcf2e130a4c05600e.png)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture

IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does

jeecgboot输出日志,@Slf4j的使用方法

Appium automation test foundation -- supplement: c/s architecture and b/s architecture description

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

JMeter login failure, extracting login token, and obtaining token problem solving
随机推荐
【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
MFC窗口滚动条用法
盘点华为云GaussDB(for Redis)六大秒级能力
Huawei simulator ENSP - hcip - Hybrid Experiment 2
8. 字符串转换整数 (atoi)
JMeter学习笔记2-图形界面简单介绍
What does ft mean in the data book table
10. regular expression matching
How keil displays Chinese annotations (simple with pictures)
6. Z 字形变换
431. encode n-ary tree as binary tree DFS
Use of JMeter counters
AfxMessageBox和MessageBox的用法
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
jeecgboot输出日志,@Slf4j的使用方法
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
You cannot right-click F12 to view the source code solution on the web page
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st