ブラシのLeetcodeタイトル - 二つの数||入力規則配列(Pythonが解決)

件名の説明:

ソリューション:

次のように要素の順序付けられた配列は、辞書は配列要素に目標値を減算する配列以外の場所に存在行われたかどうか、を示している形で使用されます。

class Solution(object):
    def twoSum(self, numbers, target):
        """
        :type numbers: List[int]
        :type target: int 
        """
        dic = {}
        for index, value in enumerate(numbers):
            dic[value] = index
        for index, value in enumerate(numbers):
            if dic.get(target - value) is not None:
                return [index+1, dic.get(target - value)+1]

結果を提出してください:

公開された248元の記事 ウォンの賞賛0 ビュー90000 +

おすすめ

転載: blog.csdn.net/lu_yunjie/article/details/104080184