{"id":1771,"date":"2021-11-22T17:20:20","date_gmt":"2021-11-22T22:20:20","guid":{"rendered":"https:\/\/www.xavignu.com\/?p=1771"},"modified":"2021-11-22T17:20:20","modified_gmt":"2021-11-22T22:20:20","slug":"leetcode-problem-167","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=1771","title":{"rendered":"LeetCode problem 167"},"content":{"rendered":"\n<p>Back online after quite some time. Lately I&#8217;ve been playing with <a href=\"https:\/\/leetcode.com\/\" target=\"_blank\" rel=\"noopener\">leetcode<\/a>, so below is solution to <a href=\"https:\/\/leetcode.com\/problems\/two-sum-ii-input-array-is-sorted\/\" target=\"_blank\" rel=\"noopener\">problem 167<\/a>. This problem is an easy one and no complex structures are needed in order to solve it.<\/p>\n\n\n\n<p>\n<pre>#!\/usr\/bin\/env python\n\n''' LeetCode problem 167 \nGiven a 1-indexed array of integers numbers that is already sorted in non-decreasing order, \nfind two numbers such that they add up to a specific target number. \nLet these two numbers be numbers[index1] and numbers[index2] where 1 <= first < second <= numbers.length.\n2 <= numbers.length <= 3 * 104\n-1000 <= numbers[i] <= 1000\nnumbers is sorted in non-decreasing order.\n-1000 <= target <= 1000\nThe tests are generated such that there is exactly one solution. '''\n\ndef twoSum(numbers, target):\n\tfor i in numbers:\n\t\tif (target - i) in numbers[numbers.index(i)+1:]:\n\t\t\treturn [numbers.index(i), numbers.index(i) + numbers[numbers.index(i)+1:].index(target - i)+1]\n\n\n#twoSum([-5, -3, -1, 0, 10], -1)\nprint(f\"{twoSum([-5, -3, -1, 0, 10], -1)}\")\n#twoSum([2, 7, 11, 15], 9)\nprint(f\"{twoSum([2,7,11,15], 9)}\")\n#twoSum([2, 3, 4], 6)\nprint(f\"{twoSum([2, 3, 4], 6)}\")\n#twoSum([5, 25, 75], 100)\nprint(f\"{twoSum([5, 25,75], 100)}\")\n#twoSum([0, 0, 3, 4], 0)\nprint(f\"{twoSum([0, 0, 3, 4], 0)}\")\n<\/pre>\n<\/p>\n\n\n\n<p>I'll try to post more often from now on. I'll try to make it at least once a week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back online after quite some time. Lately I&#8217;ve been playing with leetcode, so below is solution to problem 167. This problem is an easy one and no complex structures are needed in order to solve it. #!\/usr\/bin\/env python &#8221;&#8217; LeetCode problem 167 Given a 1-indexed array of integers numbers that is already sorted in non-decreasing [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[92,62,114],"tags":[56,115,6,67,70],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-sz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1771"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1771"}],"version-history":[{"count":4,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1771\/revisions"}],"predecessor-version":[{"id":1775,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1771\/revisions\/1775"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}