[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"searchBlogPosts":3,"$f67KxKJpXsafrWqCCFbOsh79C5JtRUWv15jnPyC_EN2w":7},[4],{"_path":5,"title":6},"\u002Fblog\u002F2023\u002F09\u002F17\u002Fspring-boot-postgresql","Spring Boot with PostgreSQL & pgAdmin in Docker",{"title":8,"category":9,"problemHtml":10,"solutions":11,"repoUrl":16},"Two Sum","LeetCode","\u003Cp class=\"difficulty Easy\">Easy\u003C\u002Fp>\u003Chr>\u003Cp>Given an array of integers \u003Ccode>nums\u003C\u002Fcode>&nbsp;and an integer \u003Ccode>target\u003C\u002Fcode>, return \u003Cem>indices of the two numbers such that they add up to \u003Ccode>target\u003C\u002Fcode>\u003C\u002Fem>.\u003C\u002Fp>\n\n\u003Cp>You may assume that each input would have \u003Cstrong>\u003Cem>exactly\u003C\u002Fem> one solution\u003C\u002Fstrong>, and you may not use the \u003Cem>same\u003C\u002Fem> element twice.\u003C\u002Fp>\n\n\u003Cp>You can return the answer in any order.\u003C\u002Fp>\n\n\u003Cp>&nbsp;\u003C\u002Fp>\n\u003Cp>\u003Cstrong class=\"example\">Example 1:\u003C\u002Fstrong>\u003C\u002Fp>\n\n\u003Cpre>\n\u003Cstrong>Input:\u003C\u002Fstrong> nums = [2,7,11,15], target = 9\n\u003Cstrong>Output:\u003C\u002Fstrong> [0,1]\n\u003Cstrong>Explanation:\u003C\u002Fstrong> Because nums[0] + nums[1] == 9, we return [0, 1].\n\u003C\u002Fpre>\n\n\u003Cp>\u003Cstrong class=\"example\">Example 2:\u003C\u002Fstrong>\u003C\u002Fp>\n\n\u003Cpre>\n\u003Cstrong>Input:\u003C\u002Fstrong> nums = [3,2,4], target = 6\n\u003Cstrong>Output:\u003C\u002Fstrong> [1,2]\n\u003C\u002Fpre>\n\n\u003Cp>\u003Cstrong class=\"example\">Example 3:\u003C\u002Fstrong>\u003C\u002Fp>\n\n\u003Cpre>\n\u003Cstrong>Input:\u003C\u002Fstrong> nums = [3,3], target = 6\n\u003Cstrong>Output:\u003C\u002Fstrong> [0,1]\n\u003C\u002Fpre>\n\n\u003Cp>&nbsp;\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Constraints:\u003C\u002Fstrong>\u003C\u002Fp>\n\n\u003Cul>\n\t\u003Cli>\u003Ccode>2 &lt;= nums.length &lt;= 10\u003Csup>4\u003C\u002Fsup>\u003C\u002Fcode>\u003C\u002Fli>\n\t\u003Cli>\u003Ccode>-10\u003Csup>9\u003C\u002Fsup> &lt;= nums[i] &lt;= 10\u003Csup>9\u003C\u002Fsup>\u003C\u002Fcode>\u003C\u002Fli>\n\t\u003Cli>\u003Ccode>-10\u003Csup>9\u003C\u002Fsup> &lt;= target &lt;= 10\u003Csup>9\u003C\u002Fsup>\u003C\u002Fcode>\u003C\u002Fli>\n\t\u003Cli>\u003Cstrong>Only one valid answer exists.\u003C\u002Fstrong>\u003C\u002Fli>\n\u003C\u002Ful>\n\n\u003Cp>&nbsp;\u003C\u002Fp>\n\u003Cstrong>Follow-up:&nbsp;\u003C\u002Fstrong>Can you come up with an algorithm that is less than \u003Ccode>O(n\u003Csup>2\u003C\u002Fsup>)\u003C\u002Fcode>\u003Cfont face=\"monospace\">&nbsp;\u003C\u002Ffont>time complexity?",[12],{"lang":13,"label":14,"html":15},"python","Python","\u003Cpre>\u003Ccode class=\"language-python\">class Solution:\n    def twoSum(self, nums: List[int], target: int) -&gt; List[int]:\n        map = {}\n        \n        for i in range(len(nums)):\n            \n            sum = target - nums[i]\n            \n            if sum in map:\n                return [i, map[sum]]\n                \n            map[nums[i]] = i\n            \n        return [-1, -1]\u003C\u002Fcode>\u003C\u002Fpre>","https:\u002F\u002Fgithub.com\u002Fvishwarajsali\u002FInterviewPrep\u002Ftree\u002Fmain\u002F0001-two-sum"]