题解 | #两数之和#

两数之和

http://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f

#
# 
# @param numbers int整型一维数组 
# @param target int整型 
# @return int整型一维数组
#
class Solution:
    def twoSum(self , numbers , target ):
        # write code here
        for i in range(len(numbers)):
            temp=target-numbers[i]
            if temp in numbers :
                j=numbers.index(temp)
                if i!=j:
                    res=[min(i+1,j+1),max(i+1,j+1)]
                    break
                else:
                    continue
            else:
                continue
        return res
全部评论
超时了
点赞 回复 分享
发布于 2023-03-06 22:56 江苏
再做减法前可以对里面元素判断一下就可以过了
点赞 回复 分享
发布于 2022-02-28 00:04
复杂度过高,不能全过啊 有没有什么办法优化下
点赞 回复 分享
发布于 2022-02-28 00:02

相关推荐

点赞 评论 收藏
分享
评论
10
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务