The six Day 数组中找出和为目标值

class Solution(object):
    """
    给定一个整数数组 nums 和一个目标值 target,
    请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
    """


def twosum(nums, target):
    """
    :type nums: List[int]
    :type target: int
    :rtype: List[int]
    """
    for i in range(len(nums)):
        for j in range(i+1, len(nums)):
            sum = nums[i] + nums[j]
            
            if sum == target:
                return i, j
            else:
                i += 1

if __name__ == '__main__':
    s = Solution()
    nums = [2, 7, 11, 15]
    target = 9
    r = twosum(nums, target)
    print(r)
    

 

上一篇:表单--Six


下一篇:iOS数据持久化文件读写之偏好设置