반응형
In this simple exercise, you will create a program that will take two lists of integers, a
and b
. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a
and b
. You must find the difference of the cuboids' volumes regardless of which is bigger.
For example, if the parameters passed are ([2, 2, 3], [5, 4, 1])
, the volume of a
is 12 and the volume of b
is 20. Therefore, the function should return 8.
Your function will be tested with pre-made examples as well as random ones.
If you can, try writing it in one line of code.
Solution:
from typing import List
def find_difference(a: List[int], b: List[int]) -> int:
return abs(get_multiply(a) - get_multiply(b))
def get_multiply(arr: List[int], result: int = 1) -> int:
for e in arr:
result*=e
return result
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0922. Love vs friendship (0) | 2022.09.22 |
---|---|
0921. Sum without highest and lowest number (0) | 2022.09.21 |
0919. Cat years, Dog years (0) | 2022.09.19 |
0918. Grasshopper - Array Mean (0) | 2022.09.19 |
0917. Largest pair sum in array (0) | 2022.09.17 |