From a5505e17f8e3a28afdc6047bddfc43b22af8d244 Mon Sep 17 00:00:00 2001 From: SCBoyChina Date: Wed, 31 Oct 2018 18:01:33 +0800 Subject: [PATCH] update: 001 --- note/001/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/note/001/README.md b/note/001/README.md index f0224222..a93e6bc6 100644 --- a/note/001/README.md +++ b/note/001/README.md @@ -44,11 +44,12 @@ class Solution { ```java class Solution { public int[] twoSum(int[] nums, int target) { - int len = nums.length; + final int len = nums.length; HashMap map = new HashMap<>(); for (int i = 0; i < len; ++i) { - if (map.containsKey(nums[i])) { - return new int[]{map.get(nums[i]), i}; + final Integer value = map.get(nums[i]); + if (value != null) { + return new int[] { value, i }; } map.put(target - nums[i], i); }