CMPSC 465 Lecture Notes - Lecture 2: Hash Table, Data Structure

64 views1 pages
9 Jul 2019
School
Course
Professor

Document Summary

Data structure that implements an array with a key and value pair. If more than one keys are the same but have different values, the oldest key that was inserted into the hash map will have a replaced value. Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Given nums = [2, 7, 11, 15], target = 9, Function should return [0,1] because nums[0] + nums[1] = 9, which is the value for the variable target. In this function, we first initiate an empty dictionary. A for-loop that iterates the array, nums, only once will compute the difference of the target value and each element in the array.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents