{"action":"created","issue":{"url":"https://api.github.com/repos/masteroy/algorithm/issues/30","repository_url":"https://api.github.com/repos/masteroy/algorithm","labels_url":"https://api.github.com/repos/masteroy/algorithm/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/masteroy/algorithm/issues/30/comments","events_url":"https://api.github.com/repos/masteroy/algorithm/issues/30/events","html_url":"https://github.com/masteroy/algorithm/issues/30","id":364127456,"node_id":"MDU6SXNzdWUzNjQxMjc0NTY=","number":30,"title":"[LeetCode] 33. Search in Rotated Sorted Array","user":{"login":"masteroy","id":7699608,"node_id":"MDQ6VXNlcjc2OTk2MDg=","avatar_url":"https://avatars0.githubusercontent.com/u/7699608?v=4","gravatar_id":"","url":"https://api.github.com/users/masteroy","html_url":"https://github.com/masteroy","followers_url":"https://api.github.com/users/masteroy/followers","following_url":"https://api.github.com/users/masteroy/following{/other_user}","gists_url":"https://api.github.com/users/masteroy/gists{/gist_id}","starred_url":"https://api.github.com/users/masteroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masteroy/subscriptions","organizations_url":"https://api.github.com/users/masteroy/orgs","repos_url":"https://api.github.com/users/masteroy/repos","events_url":"https://api.github.com/users/masteroy/events{/privacy}","received_events_url":"https://api.github.com/users/masteroy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-26T17:07:34Z","updated_at":"2018-09-26T17:08:00Z","closed_at":null,"author_association":"OWNER","body":"Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.\r\n\r\n(i.e., `[0,1,2,4,5,6,7]` might become `[4,5,6,7,0,1,2]`).\r\n\r\nYou are given a target value to search. If found in the array return its index, otherwise return -1.\r\n\r\nYou may assume no duplicate exists in the array.\r\n\r\nYour algorithm's runtime complexity must be in the order of O(log n).\r\n\r\n**Example 1:**\r\n\r\n```\r\nInput: nums = [4,5,6,7,0,1,2], target = 0\r\nOutput: 4\r\n```\r\n**Example 2:**\r\n\r\n```\r\nInput: nums = [4,5,6,7,0,1,2], target = 3\r\nOutput: -1\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/masteroy/algorithm/issues/comments/424795733","html_url":"https://github.com/masteroy/algorithm/issues/30#issuecomment-424795733","issue_url":"https://api.github.com/repos/masteroy/algorithm/issues/30","id":424795733,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDc5NTczMw==","user":{"login":"masteroy","id":7699608,"node_id":"MDQ6VXNlcjc2OTk2MDg=","avatar_url":"https://avatars0.githubusercontent.com/u/7699608?v=4","gravatar_id":"","url":"https://api.github.com/users/masteroy","html_url":"https://github.com/masteroy","followers_url":"https://api.github.com/users/masteroy/followers","following_url":"https://api.github.com/users/masteroy/following{/other_user}","gists_url":"https://api.github.com/users/masteroy/gists{/gist_id}","starred_url":"https://api.github.com/users/masteroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masteroy/subscriptions","organizations_url":"https://api.github.com/users/masteroy/orgs","repos_url":"https://api.github.com/users/masteroy/repos","events_url":"https://api.github.com/users/masteroy/events{/privacy}","received_events_url":"https://api.github.com/users/masteroy/received_events","type":"User","site_admin":false},"created_at":"2018-09-26T17:08:00Z","updated_at":"2018-09-26T17:08:00Z","author_association":"OWNER","body":"``` javascript\r\n/**\r\n * @param {number[]} nums\r\n * @param {number} target\r\n * @return {number}\r\n */\r\nvar search = function(nums, target) {\r\n    let l = 0;\r\n    let r = nums.length - 1;\r\n    while (l <= r) {\r\n        let m = Math.floor((l + r) / 2);\r\n        if (nums[m] === target) {\r\n            return m;\r\n        } else  if (nums[m] > target) {\r\n            if (nums[m] > nums[r] && nums[l] > target) {\r\n                l = m + 1;\r\n            } else {\r\n                r = m - 1;\r\n            }\r\n        } else {\r\n            if (nums[m] < nums[r] && nums[r] < target) {\r\n                r = m - 1;\r\n            } else {\r\n                l = m + 1;\r\n            }\r\n        }\r\n    }\r\n    return -1;\r\n};\r\n```"}}
{"actor":{"display_login":"masteroy"}}