第一题twosum问题为啥我只能过28%
def find_children(candiesNeed, candies): # write code here candies.sort() res = [] left = 0 right = len(candies) - 1 while left < right: num = candies[left] + candies[right] low = candies[left] high = candies[right] if num < candiesNeed: while left < right and candies[left] == low: left += 1 elif num > candiesNeed: while left < right and candies[right] == high: right -= 1 else: res.append([left,high]) while left < right and candies[left] == low: left += 1 while left < right and candies[right] == high: right -= 1 if res: return res[0] else: return [-1, -1]
全部评论
(2) 回帖