In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to find the largest element in the array by Java". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how Java finds the largest element in the array".
Topic: given two arrays nums1 and nums2,nums1 are a subset of nums2. Find the next larger element in all the elements in the nums1 that corresponds to the nums2 location. If there is this larger element, return this element, if not-1.
Train of thought:
1. Pick out a pair of elements in nums2 that are larger than the previous one and write them to the associated container unordered_map for recording.
two。 Check to see if the element in nums1 exists in unordered_map, and if so, take out the value, and if no-1 is returned.
Language: cpp
Class Solution {public:vector nextGreaterElement (vector& findNums, vector& nums) {stack snatch unorderedmap m / / traversing the element for (auto e: nums) {/ / stack s in nums is empty and the element at the top of stack s is less than e element. Write the element into map. The key value is the top element of the stack, and the value value is the element while (! s.empty () & & s.top () < e) {m [s.top ()] = e; s.pop () } s.push (e);} vector ans;// looks for elements in findNums, returns the valuse value of m [n] if n exists in m, and returns-1for (auto n: findNums) {ans.push_back (m.count (n)? M [n]:-1);} return ans;}}; at this point, I believe you have a better understanding of "how Java finds the largest element in the array". You might as well do it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.