To the Top
File:  root - text - article - 2019 - 10 - two-sum.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 1193 Views, 15444 Search Bots | 76 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Facebook:

You are given a list of numbers, and a target number k. Return whether or not there are two numbers in the list that add up to k.

Example:
Given [4, 7, 1 , -3, 2] and k = 5,
return true since 4 + 1 = 5.


def two_sum(list, k):
# Fill this in.

print two_sum([4,7,1,-3,2], 5)
# True


Try to do it in a single pass of the list.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 1193 Views, 15444 Search Bots | 76 Words Subscribe to Feed Burner

Related Articles

  1. Algorithm Interview: String Compression
  2. Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
  3. Daily Interview Question: Edit Distance
  4. Fibonacci coding
  5. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
  6. [Daily Problem] Move Zeros
  7. Daily Interview Problem: Arithmetic Binary Tree
  8. Daily Interview Problem: Given two arrays, write a function to compute their intersection.
  9. Longest Substring Without Repeating Characters
  10. Progess made

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />