From fd04e45d8740c4be44e22a7cbf266521257a252d Mon Sep 17 00:00:00 2001 From: Amar Date: Thu, 1 Oct 2020 23:32:30 +0530 Subject: [PATCH] Java code --- LeetCode/1.two-sum.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/LeetCode/1.two-sum.cpp b/LeetCode/1.two-sum.cpp index dcfb62f..992760c 100644 --- a/LeetCode/1.two-sum.cpp +++ b/LeetCode/1.two-sum.cpp @@ -5,19 +5,20 @@ */ // @lc code=start -#include class Solution { -public: - vector twoSum(vector& nums, int target) { - map id; - for(int i = 0; i < nums.size(); i++) { - int make = target - nums[i]; - if(id[make]) { - return {id[make]-1, i}; - } - id[nums[i]] = i+1; + public int[] twoSum(int[] nums, int target) { + HashMapmap =new HashMap<>(); + + for(int i=0; i