leetcode算法:Next Greater Element I You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. The Next Greater Number of a number x in nums1 i...
classSolution { publicint[] nextGreaterElement(int[] nums1,int[] nums2) { intl1 = nums1.length, l2 = nums2.length; int[] res =newint[l1]; for(inti =0; i < l1; i++){ for(intj =0; j < l2; j++){ if(nums2[j] != nums1[i])//locate the number in nums2 continue; ...
For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1. For number 1 in the first array, the next greater number for it in the second array is 3. For number 2 in the first array, there is no next greater number for it...
Can you solve this real interview question? Next Greater Element I - The next greater element of some element x in an array is the first greater element that is to the right of x in the same array. You are given two distinct 0-indexed integer arrays num
[LeetCode] 496. Next Greater Element I 题目内容 https://leetcode-cn.com/problems/next-greater-element-i/ 给定两个没有重复元素的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集。找到 nums1 中每个元素在 nums2 中的下一个比其大的值。 ......
public class Solution { public int[] nextGreaterElement(int[] findNums, int[] nums) { if (findNums == null || nums == null) { return null; } int findLength = findNums.length; int numsLength = nums.length; int[] result = new int[findLength]; ...
class Solution(object): def nextGreaterElement(self,nums1,nums2): stk=[] #单调栈 hashTable={} #哈希表 for i in range(len(nums2)-1,-1,-1): #反向遍历 print(i) cur=nums2[i] while stk!=[] and stk[-1]<=cur: #关键 stk.pop() ...
简介:LeetCode之Next Greater Element I 1、题目 You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.The Next Greater Number of a number x in...
LeetCode 496. Next Greater Element I You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. The Next Greater Number of a number x in nums1...
public class Solution { public int[] nextGreaterElement(int[] findNums, int[] nums) { if (findNums == null || nums == null) { return null; } int findLength = findNums.length; int numsLength = nums.length; int[] result = new int[findLength]; ...