{"action":"opened","number":30,"pull_request":{"url":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/30","id":229877301,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI5ODc3MzAx","html_url":"https://github.com/xshahq/awesome-leetcode/pull/30","diff_url":"https://github.com/xshahq/awesome-leetcode/pull/30.diff","patch_url":"https://github.com/xshahq/awesome-leetcode/pull/30.patch","issue_url":"https://api.github.com/repos/xshahq/awesome-leetcode/issues/30","number":30,"state":"open","locked":false,"title":"1","user":{"login":"xshahq","id":39392552,"node_id":"MDQ6VXNlcjM5MzkyNTUy","avatar_url":"https://avatars0.githubusercontent.com/u/39392552?v=4","gravatar_id":"","url":"https://api.github.com/users/xshahq","html_url":"https://github.com/xshahq","followers_url":"https://api.github.com/users/xshahq/followers","following_url":"https://api.github.com/users/xshahq/following{/other_user}","gists_url":"https://api.github.com/users/xshahq/gists{/gist_id}","starred_url":"https://api.github.com/users/xshahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xshahq/subscriptions","organizations_url":"https://api.github.com/users/xshahq/orgs","repos_url":"https://api.github.com/users/xshahq/repos","events_url":"https://api.github.com/users/xshahq/events{/privacy}","received_events_url":"https://api.github.com/users/xshahq/received_events","type":"User","site_admin":false},"body":"# 1. Two Sum\r\n\r\n**<font color=red>难度: Easy</font>**\r\n\r\n## 刷题内容\r\n\r\n> 原题连接\r\n\r\n* https://leetcode.com/problems/two-sum\r\n\r\n> 内容描述\r\n\r\n```\r\nGiven an array of integers, return indices of the two numbers such that they add up to a specific target.\r\n\r\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\r\n\r\nExample:\r\n\r\nGiven nums = [2, 7, 11, 15], target = 9,\r\n\r\nBecause nums[0] + nums[1] = 2 + 7 = 9,\r\nreturn [0, 1].\r\n```\r\n\r\n## 解题方案\r\n\r\n> 思路 1\r\n******- 时间复杂度: O(N^2)******- 空间复杂度: O(1)******\r\n\r\n暴力解法，两轮遍历\r\n\r\nbeats 27.6%\r\n```python\r\nclass Solution(object):\r\n    def twoSum(self, nums, target):\r\n        \"\"\"\r\n        :type nums: List[int]\r\n        :type target: int\r\n        :rtype: List[int]\r\n        \"\"\"\r\n        for i in range(len(nums)):\r\n            for j in range(i+1, len(nums)):\r\n                if nums[i] + nums[j] == target:\r\n                    return [i, j]\r\n        return []\r\n```\r\n\r\n\r\n> 思路 2\r\n******- 时间复杂度: O(N)******- 空间复杂度: O(N)******\r\n\r\n上面的思路1太慢了，我们可以牺牲空间换取时间\r\n\r\n```\r\n          2        7        11    15\r\n         不存在   存在之中\r\nlookup   {2:0}    [0，1]\r\n```\r\n\r\n* 建立字典 lookup 存放第一个数字，并存放该数字的 index\r\n* 判断 lookup 种是否存在： `target - 当前数字`， 则表面 当前值和 lookup中的值加和为 target.\r\n* 如果存在，则返回：  `target - 当前数字` 的 index 和 当前值的 index\r\n\r\n```python\r\nclass Solution(object):\r\n    def twoSum(self, nums, target):\r\n        \"\"\"\r\n        :type nums: List[int]\r\n        :type target: int\r\n        :rtype: List[int]\r\n        \"\"\"\r\n        look_up = {}\r\n        for i, num in enumerate(nums):\r\n            if target-num in look_up:\r\n                return [look_up[target-num], i]\r\n            look_up[num] = i\r\n        return []\r\n```\r\n","created_at":"2018-11-10T08:03:22Z","updated_at":"2018-11-10T08:03:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/30/commits","review_comments_url":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/30/comments","review_comment_url":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xshahq/awesome-leetcode/issues/30/comments","statuses_url":"https://api.github.com/repos/xshahq/awesome-leetcode/statuses/8b527ba978d73eabe78a960484e56d0fef5a0ad1","head":{"label":"apachecn:master","ref":"master","sha":"8b527ba978d73eabe78a960484e56d0fef5a0ad1","user":{"login":"apachecn","id":24802038,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI0ODAyMDM4","avatar_url":"https://avatars3.githubusercontent.com/u/24802038?v=4","gravatar_id":"","url":"https://api.github.com/users/apachecn","html_url":"https://github.com/apachecn","followers_url":"https://api.github.com/users/apachecn/followers","following_url":"https://api.github.com/users/apachecn/following{/other_user}","gists_url":"https://api.github.com/users/apachecn/gists{/gist_id}","starred_url":"https://api.github.com/users/apachecn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apachecn/subscriptions","organizations_url":"https://api.github.com/users/apachecn/orgs","repos_url":"https://api.github.com/users/apachecn/repos","events_url":"https://api.github.com/users/apachecn/events{/privacy}","received_events_url":"https://api.github.com/users/apachecn/received_events","type":"Organization","site_admin":false},"repo":{"id":105229748,"node_id":"MDEwOlJlcG9zaXRvcnkxMDUyMjk3NDg=","name":"awesome-algorithm","full_name":"apachecn/awesome-algorithm","private":false,"owner":{"login":"apachecn","id":24802038,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI0ODAyMDM4","avatar_url":"https://avatars3.githubusercontent.com/u/24802038?v=4","gravatar_id":"","url":"https://api.github.com/users/apachecn","html_url":"https://github.com/apachecn","followers_url":"https://api.github.com/users/apachecn/followers","following_url":"https://api.github.com/users/apachecn/following{/other_user}","gists_url":"https://api.github.com/users/apachecn/gists{/gist_id}","starred_url":"https://api.github.com/users/apachecn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apachecn/subscriptions","organizations_url":"https://api.github.com/users/apachecn/orgs","repos_url":"https://api.github.com/users/apachecn/repos","events_url":"https://api.github.com/users/apachecn/events{/privacy}","received_events_url":"https://api.github.com/users/apachecn/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/apachecn/awesome-algorithm","description":"Leetcode 题解 (跟随思路一步一步撸出代码) 及经典算法实现","fork":false,"url":"https://api.github.com/repos/apachecn/awesome-algorithm","forks_url":"https://api.github.com/repos/apachecn/awesome-algorithm/forks","keys_url":"https://api.github.com/repos/apachecn/awesome-algorithm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apachecn/awesome-algorithm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apachecn/awesome-algorithm/teams","hooks_url":"https://api.github.com/repos/apachecn/awesome-algorithm/hooks","issue_events_url":"https://api.github.com/repos/apachecn/awesome-algorithm/issues/events{/number}","events_url":"https://api.github.com/repos/apachecn/awesome-algorithm/events","assignees_url":"https://api.github.com/repos/apachecn/awesome-algorithm/assignees{/user}","branches_url":"https://api.github.com/repos/apachecn/awesome-algorithm/branches{/branch}","tags_url":"https://api.github.com/repos/apachecn/awesome-algorithm/tags","blobs_url":"https://api.github.com/repos/apachecn/awesome-algorithm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apachecn/awesome-algorithm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apachecn/awesome-algorithm/git/refs{/sha}","trees_url":"https://api.github.com/repos/apachecn/awesome-algorithm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apachecn/awesome-algorithm/statuses/{sha}","languages_url":"https://api.github.com/repos/apachecn/awesome-algorithm/languages","stargazers_url":"https://api.github.com/repos/apachecn/awesome-algorithm/stargazers","contributors_url":"https://api.github.com/repos/apachecn/awesome-algorithm/contributors","subscribers_url":"https://api.github.com/repos/apachecn/awesome-algorithm/subscribers","subscription_url":"https://api.github.com/repos/apachecn/awesome-algorithm/subscription","commits_url":"https://api.github.com/repos/apachecn/awesome-algorithm/commits{/sha}","git_commits_url":"https://api.github.com/repos/apachecn/awesome-algorithm/git/commits{/sha}","comments_url":"https://api.github.com/repos/apachecn/awesome-algorithm/comments{/number}","issue_comment_url":"https://api.github.com/repos/apachecn/awesome-algorithm/issues/comments{/number}","contents_url":"https://api.github.com/repos/apachecn/awesome-algorithm/contents/{+path}","compare_url":"https://api.github.com/repos/apachecn/awesome-algorithm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apachecn/awesome-algorithm/merges","archive_url":"https://api.github.com/repos/apachecn/awesome-algorithm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apachecn/awesome-algorithm/downloads","issues_url":"https://api.github.com/repos/apachecn/awesome-algorithm/issues{/number}","pulls_url":"https://api.github.com/repos/apachecn/awesome-algorithm/pulls{/number}","milestones_url":"https://api.github.com/repos/apachecn/awesome-algorithm/milestones{/number}","notifications_url":"https://api.github.com/repos/apachecn/awesome-algorithm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apachecn/awesome-algorithm/labels{/name}","releases_url":"https://api.github.com/repos/apachecn/awesome-algorithm/releases{/id}","deployments_url":"https://api.github.com/repos/apachecn/awesome-algorithm/deployments","created_at":"2017-09-29T04:26:40Z","updated_at":"2018-11-10T07:57:20Z","pushed_at":"2018-11-10T07:57:18Z","git_url":"git://github.com/apachecn/awesome-algorithm.git","ssh_url":"git@github.com:apachecn/awesome-algorithm.git","clone_url":"https://github.com/apachecn/awesome-algorithm.git","svn_url":"https://github.com/apachecn/awesome-algorithm","homepage":"","size":23379,"stargazers_count":6786,"watchers_count":6786,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1103,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":1103,"open_issues":2,"watchers":6786,"default_branch":"master"}},"base":{"label":"xshahq:master","ref":"master","sha":"7c82669fd657ba0f02fe3788b8d562ccf56c1669","user":{"login":"xshahq","id":39392552,"node_id":"MDQ6VXNlcjM5MzkyNTUy","avatar_url":"https://avatars0.githubusercontent.com/u/39392552?v=4","gravatar_id":"","url":"https://api.github.com/users/xshahq","html_url":"https://github.com/xshahq","followers_url":"https://api.github.com/users/xshahq/followers","following_url":"https://api.github.com/users/xshahq/following{/other_user}","gists_url":"https://api.github.com/users/xshahq/gists{/gist_id}","starred_url":"https://api.github.com/users/xshahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xshahq/subscriptions","organizations_url":"https://api.github.com/users/xshahq/orgs","repos_url":"https://api.github.com/users/xshahq/repos","events_url":"https://api.github.com/users/xshahq/events{/privacy}","received_events_url":"https://api.github.com/users/xshahq/received_events","type":"User","site_admin":false},"repo":{"id":149982005,"node_id":"MDEwOlJlcG9zaXRvcnkxNDk5ODIwMDU=","name":"awesome-leetcode","full_name":"xshahq/awesome-leetcode","private":false,"owner":{"login":"xshahq","id":39392552,"node_id":"MDQ6VXNlcjM5MzkyNTUy","avatar_url":"https://avatars0.githubusercontent.com/u/39392552?v=4","gravatar_id":"","url":"https://api.github.com/users/xshahq","html_url":"https://github.com/xshahq","followers_url":"https://api.github.com/users/xshahq/followers","following_url":"https://api.github.com/users/xshahq/following{/other_user}","gists_url":"https://api.github.com/users/xshahq/gists{/gist_id}","starred_url":"https://api.github.com/users/xshahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xshahq/subscriptions","organizations_url":"https://api.github.com/users/xshahq/orgs","repos_url":"https://api.github.com/users/xshahq/repos","events_url":"https://api.github.com/users/xshahq/events{/privacy}","received_events_url":"https://api.github.com/users/xshahq/received_events","type":"User","site_admin":false},"html_url":"https://github.com/xshahq/awesome-leetcode","description":"Leetcode 题解 (跟随思路一步一步撸出代码) 及经典算法实现","fork":true,"url":"https://api.github.com/repos/xshahq/awesome-leetcode","forks_url":"https://api.github.com/repos/xshahq/awesome-leetcode/forks","keys_url":"https://api.github.com/repos/xshahq/awesome-leetcode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xshahq/awesome-leetcode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xshahq/awesome-leetcode/teams","hooks_url":"https://api.github.com/repos/xshahq/awesome-leetcode/hooks","issue_events_url":"https://api.github.com/repos/xshahq/awesome-leetcode/issues/events{/number}","events_url":"https://api.github.com/repos/xshahq/awesome-leetcode/events","assignees_url":"https://api.github.com/repos/xshahq/awesome-leetcode/assignees{/user}","branches_url":"https://api.github.com/repos/xshahq/awesome-leetcode/branches{/branch}","tags_url":"https://api.github.com/repos/xshahq/awesome-leetcode/tags","blobs_url":"https://api.github.com/repos/xshahq/awesome-leetcode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xshahq/awesome-leetcode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xshahq/awesome-leetcode/git/refs{/sha}","trees_url":"https://api.github.com/repos/xshahq/awesome-leetcode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xshahq/awesome-leetcode/statuses/{sha}","languages_url":"https://api.github.com/repos/xshahq/awesome-leetcode/languages","stargazers_url":"https://api.github.com/repos/xshahq/awesome-leetcode/stargazers","contributors_url":"https://api.github.com/repos/xshahq/awesome-leetcode/contributors","subscribers_url":"https://api.github.com/repos/xshahq/awesome-leetcode/subscribers","subscription_url":"https://api.github.com/repos/xshahq/awesome-leetcode/subscription","commits_url":"https://api.github.com/repos/xshahq/awesome-leetcode/commits{/sha}","git_commits_url":"https://api.github.com/repos/xshahq/awesome-leetcode/git/commits{/sha}","comments_url":"https://api.github.com/repos/xshahq/awesome-leetcode/comments{/number}","issue_comment_url":"https://api.github.com/repos/xshahq/awesome-leetcode/issues/comments{/number}","contents_url":"https://api.github.com/repos/xshahq/awesome-leetcode/contents/{+path}","compare_url":"https://api.github.com/repos/xshahq/awesome-leetcode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xshahq/awesome-leetcode/merges","archive_url":"https://api.github.com/repos/xshahq/awesome-leetcode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xshahq/awesome-leetcode/downloads","issues_url":"https://api.github.com/repos/xshahq/awesome-leetcode/issues{/number}","pulls_url":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls{/number}","milestones_url":"https://api.github.com/repos/xshahq/awesome-leetcode/milestones{/number}","notifications_url":"https://api.github.com/repos/xshahq/awesome-leetcode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xshahq/awesome-leetcode/labels{/name}","releases_url":"https://api.github.com/repos/xshahq/awesome-leetcode/releases{/id}","deployments_url":"https://api.github.com/repos/xshahq/awesome-leetcode/deployments","created_at":"2018-09-23T12:23:59Z","updated_at":"2018-11-09T14:29:54Z","pushed_at":"2018-11-09T14:29:53Z","git_url":"git://github.com/xshahq/awesome-leetcode.git","ssh_url":"git@github.com:xshahq/awesome-leetcode.git","clone_url":"https://github.com/xshahq/awesome-leetcode.git","svn_url":"https://github.com/xshahq/awesome-leetcode","homepage":"","size":23378,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/30"},"html":{"href":"https://github.com/xshahq/awesome-leetcode/pull/30"},"issue":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/issues/30"},"comments":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/xshahq/awesome-leetcode/statuses/8b527ba978d73eabe78a960484e56d0fef5a0ad1"}},"author_association":"OWNER","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":2,"additions":1,"deletions":1,"changed_files":1}}
{"actor":{"display_login":"xshahq"}}