LeetCode 1. 两数之和
题目连接:https://leetcode-cn.com/problems/two-sum/
Java解法:
public int[] twoSum(int[] nums, int target) { Map<Integer, Integer> used = new HashMap<>(); for (int i = 0; i < nums.length; i++) { int com = target - nums[i]; if (used.containsKey(com) && used.get(com) != i) { return new int[]{used.get(com), i}; } used.put(nums[i], i); } return new int[0]; }
不在代码中爆发,就在代码灭亡!
========================================================================