[] 42. Offer to prove safety and implemented as the two numbers python S

Title Description

An incrementing input and a digital sorted array S, find the two numbers in the array, and so that they are exactly S, and if a plurality of digits equal to S, the product of the output of the minimum number of two.

Output Description:

Corresponding to each test case, the output of two numbers, the first small output.

Examples

Examples:
[1,2,4,7,11,15], 15

The corresponding output should be:

[4,11]

# -*- coding:utf-8 -*-
class Solution:
    def FindNumbersWithSum(self, array, tsum):
        # write code here
        k = 0
        count = 0
        for i in array:
            k += 1
            for j in array[k:]:
                sumres = i
                sumres += j
                if sumres == tsum:
                    count += 1
                    return i,j
        if count == 0:
            return []
Published 99 original articles · won praise 6 · views 3951

Guess you like

Origin blog.csdn.net/weixin_42247922/article/details/104022892