From 4df208c6eba983fbc20c463298e4dcd2076af0de Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 25 Jan 2020 09:24:42 -0500 Subject: [PATCH] 2020-01-25 --- ...\270\244\346\225\260\344\271\213\345\222\214.py" | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git "a/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" "b/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" index 9442d88..8b92177 100644 --- "a/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" +++ "b/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" @@ -5,11 +5,8 @@ def twoSum(self, nums, target): :type target: int :rtype: List[int] """ - hashmap = {} - for i, x in enumerate(nums): - if hashmap.has_key(target - x): - return [hashmap[target - x], i] - else: - hashmap[x] = i - - return [] \ No newline at end of file + dic = {} + for i, num in enumerate(nums): + if target - num in dic: + return [dic[target - num], i] + dic[num] = i \ No newline at end of file