馬哥高端Go語(yǔ)言百萬(wàn)并發(fā)高xin班微服務(wù)分布式高可用 Go高并發(fā)2022
public static int[] twoSum2(int[] nums, int target) {
? ? ? ?Map<Integer, Integer> map = new HashMap<>();
? ? ? ?for(int i = 0; i<nums.length;i++) {
? ? ? ? ? ?map.put(nums[i], i);
? ? ? ?}
? ? ? ?
? ? ? ?for(int i = 0;i<nums.length;i++) {
? ? ? ? ? ?int c = target - nums[i];
? ? ? ? ? ?if(map.containsKey(c) && map.get(c) != i) {
? ? ? ? ? ? ? ?return new int[] {i,map.get(c)};
? ? ? ? ? ?}
? ? ? ?} ? ? ?
? ? ? ?throw new IllegalArgumentException("沒(méi)找到"); ?
? ?}
標(biāo)簽: