leetcode--1:(python)Two Sum
2019.5.25: #1
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.
Example:
我的解法:
这种思维上比较直观,就是把索引号全做一个配对,按照配对逐个试。但是python是分离式链表,对于这种一直查表的操作十分缓慢。。。何况每次尝试都要查两次表
厉害的解法:利用字典,把元素作为key,该次尝试的索引号作为value,每次的差值都和key做比较相同就return不同就加入字典等待以后能匹配,每次只查一次表而且不会重复工作。