class Solution(object): def twoSum(self, nums, target): if len(nums) <= 1: return False buff_dict = {} for i in range(len(nums)): if nums[i] in buff_dict: return [buff_dict[nums[i]], i] else: buff_dict[target - nums[i]] = i <!--more--> """ def main(): nums = [2, 7, 11, 15] target = 9 s = Solution() print(s.twoSum(nums, target)) """ if __name__ == "__main__": nums = [2, 7, 11, 15] target = 9 s = Solution() print(s.twoSum(nums, target))
|
近期评论