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); }