LeetCode 标签

[日常 LeetCode] 1.Two Sum 有更新!

  |   2 评论   |   101 浏览

很简单的一道题目: 1.Two Sum Given an array of integers, returnindicesof the two numbers such that they add up to a specific target. You may assume that each input would have**exactly**one solution, and you may not use the_same_element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. 第一次写的: class Solution: def twoSum(self, nums, target: int) : for i in range(0,len(nums)): for j in range(i+1,len(nums)): if i!=j and nums[i] + nums[j] == ....