当前位置:网站首页>[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
};
```
边栏推荐
- Pytorch training deep learning network settings CUDA specified GPU visible
- 不同性能测试工具的并发模式
- Develop industrial Internet with the technical advantages of small programs
- [TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
- [ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
- [reach out to Party welfare] developer reload system sequence
- 在 C 中声明函数之前调用函数会发生什么?
- 389. 找不同
- Network metering - application layer
- Explain spark operation mode in detail (local+standalone+yarn)
猜你喜欢

不同性能测试工具的并发模式

The combination of applet container technology and IOT

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

Sort linked list (merge sort)
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

Web components series (VIII) -- custom component style settings

Future of NTF and trends in 2022

Deep learning | rnn/lstm of naturallanguageprocessing

TEC: Knowledge Graph Embedding with Triple Context

Network metering - application layer
随机推荐
互联网行业最佳产品开发流程 推荐!
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
在线公网安备案保姆级教程【伸手党福利】
C语言的sem_t变量类型
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
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
What happens when a function is called before it is declared in C?
Web components series (VIII) -- custom component style settings
6. zigzag transformation
Usage of AfxMessageBox and MessageBox
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
Appium自动化测试基础--补充:C/S架构和B/S架构说明
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
[TA frost wolf \u may - "hundred people plan"] 2.1 color space
Unexpected token o in JSON at position 1, JSON parsing problem
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
【伸手党福利】JSONObject转String保留空字段
171. excel table column No
The programmer's girlfriend gave me a fatigue driving test
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation