Programming_prob/Codesignal
[Intro] adjacentElementsProduct
YongArtist
2020. 7. 18. 14:51
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
주어진 정수 배열에서, 곱이 가장 큰 인접한 요소쌍을 찾아서 곱의 값을 반환한다.
def adjacentElementsProduct(inputArray):
return max([inputArray[i] * inputArray[i + 1] for i in range(len(inputArray) - 1)])
각각의 인접한 요소쌍의 곱의 값들을 리스트에 저장하고, max()를 통해 최댓값을 구하여 반환한다.