Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How python rotates the minimum number of an array

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "python how to rotate the minimum number of the array", the content is detailed, the steps are clear, the details are handled properly, I hope this "python how to rotate the minimum number of the array" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

Title

Moving the first elements of an array to the end of the array is called the rotation of the array. Enter a rotation of a non-descending array and output the smallest element of the rotation array. For example, the array [3pyrmus 4pyrr5] is a rotation of [1pyrmol 2pyrm 3pyrm 4pyr5], and the minimum value of this array is 1. NOTE: all elements given are greater than 0. If the array size is 0, return 0.

Problem-solving ideas

Dichotomy

Code #-*-coding:utf-8-*-class Solution: def minNumberInRotateArray (self RotateArray): start = 0 end= len (rotateArray)-1 mid = end//2 if end==0: return 0 while 1: if rotateArray [start] > rotateArray [mid]: end= mid mid = (start+mid) / / 2 elif rotateArray [end] < rotateArray [mid]: start = mid Mid = (mid+end) / / 2 if rotateArray [mid] = = rotateArray [start] or rotateArray [mid] = = rotateArray [end]: break return rotateArray [mid+1] here This article "how to rotate the minimum number of python array" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the article, please 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report