Continuing from Last time, I am reading the search problem. Here, the value is searched from the relationship with other values to find the maximum value.
const int ARRAY_SIZE = 10;
int intArray[ARRAY_SIZE] = {4,5,9,12,-4,0,-57,30987,-287,1};
int highestValue = intArray[0];
for (int i = 1; i < ARRAY_SIZE; i++) {
if (intArray[i] > highestValue) highestValue = intArray[i];
#!/usr/bin/env python
#coding:utf-8
def MaxSearch():
ARRAY_NUMBER = [4,5,9,12,-4,0,-57,30987,-287,1]
maxValue = ARRAY_NUMBER[0]
for x in range(len(ARRAY_NUMBER)):
if ARRAY_NUMBER[x] > maxValue:
maxValue = ARRAY_NUMBER[x]
print(maxValue)
・ ・ ・ (Terminal execution)
>>> from test31 import MaxSearch
>>> MaxSearch()
30987
>>>
Refer to the previous comment I intended to shorten it myself, but the maximum value was requested!
For reference from the previous comment Is there a Python method Python standard library I searched here, but I couldn't find anything that seems to be a method to find the maximum value. So is it better to look at the maximum values in order?
Recommended Posts