. - 力扣(LeetCode)
from typing import List
# 直接求就行,其中当target大于最后一位求余的数字时,是不可能会等于target的
class Solution:
def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]:
good_list = []
for index, item in enumerate(variables):
if item[-1] <= target:
continue
if (item[0] ** item[1] % 10) ** item[2] % item[3] == target:
good_list.append(index)
return good_list
# python 的pow()函数可以用于幂运算和求模幂运算。
def getGoodIndicesExpend(self, variables: List[List[int]], target: int) -> List[int]:
good_list = []
for index, item in enumerate(variables):
if item[-1] <= target:
continue
if pow(pow(item[0], item[1], 10), item[2], item[3]) == target:
good_list.append(index)
return good_list
# 使用列表推导式
def getGoodIndicesMoreExpend(self, variables: List[List[int]], target: int) -> List[int]:
return [index for index, item in enumerate(variables) if
item[-1] >= target and pow(pow(item[0], item[1], 10), item[2], item[3]) == target]