{"ScriptPreparationCode":null,"TestCases":[{"Name":"brute force","Code":"var twoSum = function(nums, target) {\r\n for(let i=0; i\u003Cnums.length; i\u002B\u002B) {\r\n for(let j=i\u002B1; j\u003Cnums.length; j\u002B\u002B) {\r\n if(nums[i]\u002Bnums[j]===target) return [i,j]\r\n }\r\n }\r\n return [];\r\n};\r\ntwoSum([2,7,11,15], 9)","IsDeferred":false},{"Name":"memo","Code":"var twoSum = function(nums, target) {\r\n let sol = [];\r\n for(let i=0; i\u003Cnums.length; i\u002B\u002B) {\r\n if(sol.length) break;\r\n for(let j=i\u002B1; j\u003Cnums.length; j\u002B\u002B) {\r\n if(sol.length) break;\r\n if(nums[i]\u002Bnums[j]===target) sol = [i,j]\r\n }\r\n }\r\n return sol;\r\n}\r\ntwoSum([2,7,11,15], 9)","IsDeferred":false},{"Name":"hash","Code":"var twoSumHash = function (nums, target)\r\n{\r\n let hashTable = []\r\n let pair = []\r\n let i = 0;\r\n let foundPair = false\r\n while (i \u003C nums.length) {\r\n hashTable[nums[i]] = i\r\n i \u002B= 1\r\n }\r\n i = 0\r\n while (i \u003C nums.length \u0026\u0026 !foundPair) {\r\n let compliment = target - nums [i]\r\n if (compliment in hashTable) {\r\n if (i !== hashTable[compliment]) {\r\n pair.push(i)\r\n pair.push(hashTable [compliment])\r\n foundPair = true\r\n }\r\n }\r\n i \u002B= 1\r\n }\r\n\r\n return pair\r\n}\r\n\r\nconsole.log(twoSumHash([2,7,11,15], 9))","IsDeferred":false}]}