{"action":"created","issue":{"url":"https://api.github.com/repos/gm8300130/leetcode/issues/42","repository_url":"https://api.github.com/repos/gm8300130/leetcode","labels_url":"https://api.github.com/repos/gm8300130/leetcode/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/gm8300130/leetcode/issues/42/comments","events_url":"https://api.github.com/repos/gm8300130/leetcode/issues/42/events","html_url":"https://github.com/gm8300130/leetcode/pull/42","id":225282368,"number":42,"title":"LeetCode 219. Contains Duplicate II","user":{"login":"gm8300130","id":20453680,"avatar_url":"https://avatars1.githubusercontent.com/u/20453680?v=3","gravatar_id":"","url":"https://api.github.com/users/gm8300130","html_url":"https://github.com/gm8300130","followers_url":"https://api.github.com/users/gm8300130/followers","following_url":"https://api.github.com/users/gm8300130/following{/other_user}","gists_url":"https://api.github.com/users/gm8300130/gists{/gist_id}","starred_url":"https://api.github.com/users/gm8300130/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gm8300130/subscriptions","organizations_url":"https://api.github.com/users/gm8300130/orgs","repos_url":"https://api.github.com/users/gm8300130/repos","events_url":"https://api.github.com/users/gm8300130/events{/privacy}","received_events_url":"https://api.github.com/users/gm8300130/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-29T20:15:29Z","updated_at":"2017-04-29T20:16:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/gm8300130/leetcode/pulls/42","html_url":"https://github.com/gm8300130/leetcode/pull/42","diff_url":"https://github.com/gm8300130/leetcode/pull/42.diff","patch_url":"https://github.com/gm8300130/leetcode/pull/42.patch"},"body":"# 題目\r\n\r\nGiven an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.\r\n\r\n# 翻譯\r\n給一個陣列nums跟一個整數k，判斷能不能在陣列中找到nums[i] = numsj，而且i跟j的距離不能比k還大。\r\n\r\n# 想法\r\n\r\n跑個for, 建立map存放出現過的數字與位置, 當有重複出現判斷位置距離是否小於等於k, 有就true, 否則跑完就直接false\r\n"},"comment":{"url":"https://api.github.com/repos/gm8300130/leetcode/issues/comments/298191953","html_url":"https://github.com/gm8300130/leetcode/pull/42#issuecomment-298191953","issue_url":"https://api.github.com/repos/gm8300130/leetcode/issues/42","id":298191953,"user":{"login":"gm8300130","id":20453680,"avatar_url":"https://avatars1.githubusercontent.com/u/20453680?v=3","gravatar_id":"","url":"https://api.github.com/users/gm8300130","html_url":"https://github.com/gm8300130","followers_url":"https://api.github.com/users/gm8300130/followers","following_url":"https://api.github.com/users/gm8300130/following{/other_user}","gists_url":"https://api.github.com/users/gm8300130/gists{/gist_id}","starred_url":"https://api.github.com/users/gm8300130/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gm8300130/subscriptions","organizations_url":"https://api.github.com/users/gm8300130/orgs","repos_url":"https://api.github.com/users/gm8300130/repos","events_url":"https://api.github.com/users/gm8300130/events{/privacy}","received_events_url":"https://api.github.com/users/gm8300130/received_events","type":"User","site_admin":false},"created_at":"2017-04-29T20:16:01Z","updated_at":"2017-04-29T20:16:01Z","body":"# 參閱\r\nhttps://skyyen999.gitbooks.io/-leetcode-with-javascript/content/questions/219md.html\r\n\r\n```\r\n/**\r\n * @param {number[]} nums\r\n * @param {number} k\r\n * @return {boolean}\r\n */\r\nvar containsNearbyDuplicate = function(nums, k) {\r\n    if(nums.length <= 1) return false;\r\n\r\n    // 使用map儲存出現過的數字\r\n    var map = {};\r\n\r\n    for(var i in nums){\r\n        var v = nums[i];\r\n\r\n        if(map[v] && (i - map[v] <= k)){\r\n            // 如果有出現重複的數字，判斷目前的位置-之前儲存的位置 <= k，符合條件return true\r\n            return true;\r\n        }\r\n        // 將出現過的數字與其位置放入map\r\n        map[v] = i;\r\n    }\r\n\r\n    // 全部跑完，沒符合條件的配對，return false\r\n    return false;\r\n};\r\n```"}}
{"actor":{"display_login":"gm8300130"}}