In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you java looking for the minimum value in the rotation sort array, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Suppose that an array sorted in ascending order is rotated at a pre-unknown point.
(for example, an array [0meme1reparent2magor455pyrr7] may become [4pyrrine 5rec 6pr 7jor0rec 1reie2]).
Please find the smallest element.
You can assume that there are no repeating elements in the array.
Example 1:
Input: [3, 4, 5, 5, 1, 2]
Output: 1
Example 2:
Input: [4, 5, 6, 7, 0, 0, 1, 2]
Output: 0
Answer:
1public int findMin (int [] nums) {
2 int start = 0, end = nums.length-1
3 while (start
< end) { 4 if (nums[start] < nums[end]) 5 return nums[start]; 6 int mid = (start + end) / 2; 7 if (nums[mid] >= nums [start]) {
8 start = mid + 1
9} else {
10 end = mid
11}
12}
13 return nums [start]
14}
Parsing:
Dichotomy search, it is easy to understand, but the array has been rotated, so it can not be fully applied, we can intercept, find in the subarray
What are the advantages of Java. Simple, as long as understand the basic concepts, you can write applications suitable for a variety of situations; 2. Object oriented; 3. Distributed, Java is a network-oriented language; 4. Robust, java provides automatic garbage collection for memory management to prevent programmers from making mistakes when managing memory. ; 5. Security, Java used in the network and distributed environment must prevent the invasion of viruses. 6. Architecturally neutral, as long as the Java runtime system is installed, it can run on any processor. 7. Portability, Java can be easily ported to different machines on the network. 8. Interpretation execution, Java interpreter directly interprets and executes Java bytecode.
These are all the contents of the article "java looking for minimum values in a rotated sorted array". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.