[Huawei OD test questions] calculate the center position of the array (python) 100% pass rate super detailed code comment code optimization

[Huawei OD machine test real questions 2022&2023] real test catalog @click here @
[Huawei OD machine test real questions] signal transmission and reception & trial reading & @click here @
[Huawei OD machine real test questions] rent a car to ride the greenway & trial reading & @点here@

the center position of the array

Time limit: 1s Space limit: 256MB Limited language: unlimited

Title description:

Given an integer array nums, please calculate the center position of the array. The center position of the array is a subscript of the array, and the product of all the elements on the left is equal to the product of all the elements on the right.
The left product of the first element of the array is 1, and the right product of the last element is 1.
If the array has multiple center positions, the one closest to the left should be returned. Returns -1 if the array does not have a center position.

Enter a description:

The input is only one line, giving

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/130672948