b站测开笔试

第一题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]

#笔试题目##哔哩哔哩#
全部评论
hashmap做
点赞
送花
回复 分享
发布于 2020-09-04 23:46
你这是排列后的索引吧,要返回的是原索引吧
点赞
送花
回复 分享
发布于 2020-09-05 09:03
秋招专场
校招火热招聘中
官网直投

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务