twoSum Algorithm : How to improve this?

前端 未结 22 2480
礼貌的吻别
礼貌的吻别 2021-02-06 01:38

I felt like doing an algorithm and found this problem on leetcode

Given an array of integers, find two numbers such that they add up to a specific target num

22条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 02:14

    Here is an O(n):

    public int[] findSumMatched(int[] numbers, int target) {
        Map mapOfNumbers = new HashMap();
        for (int i = 0; i

提交回复
热议问题