File: root - text - article - 2019 - 10 - two-sum.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 1491 Views, 19186 Search Bots | 76 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 1491 Views, 19186 Search Bots | 76 Words
| 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.
Try to do it in a single pass of the list.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 1491 Views, 19186 Search Bots | 76 Words 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.
Related Articles
- Daily Interview Puzzle: Intersection of Linked Lists
- Skip the readings, focus on problems. And use all the hints!
- Daily Interview Problem: Largest BST in a Binary Tree
- Compare Version Numbers
- Daily Interview Problem: Given two arrays, write a function to compute their intersection.
- Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
- Daily Interview Problem: Reverse Words in a String
- Daily Interview Problem: Trapping Rainwater
- Reverse a Directed Graph
- Daily Interview Problem: Arithmetic Binary Tree
©2006~2024 SteakOverCooked - 0.00863 Seconds(s) - 2162.017 KB/s - 23 Online Memory: 491.11 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !