{"action":"created","issue":{"url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5","repository_url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues","labels_url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5/comments","events_url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5/events","html_url":"https://github.com/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5","id":165097827,"number":5,"title":"模拟  2016-7-13","user":{"login":"dayang","id":8947043,"avatar_url":"https://avatars.githubusercontent.com/u/8947043?v=3","gravatar_id":"","url":"https://api.github.com/users/dayang","html_url":"https://github.com/dayang","followers_url":"https://api.github.com/users/dayang/followers","following_url":"https://api.github.com/users/dayang/following{/other_user}","gists_url":"https://api.github.com/users/dayang/gists{/gist_id}","starred_url":"https://api.github.com/users/dayang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dayang/subscriptions","organizations_url":"https://api.github.com/users/dayang/orgs","repos_url":"https://api.github.com/users/dayang/repos","events_url":"https://api.github.com/users/dayang/events{/privacy}","received_events_url":"https://api.github.com/users/dayang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-12T14:42:10Z","updated_at":"2016-07-13T14:14:49Z","closed_at":null,"body":"LeetCode 146 [LRU Cache](https://leetcode.com/problems/lru-cache/)\r\n\r\npoj 1676 [What time is it?](http://poj.org/problem?id=1676)"},"comment":{"url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/comments/232368146","html_url":"https://github.com/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5#issuecomment-232368146","issue_url":"https://api.github.com/repos/SHU-2016-SummerPractice/AlgorithmExerciseIssues/issues/5","id":232368146,"user":{"login":"dayang","id":8947043,"avatar_url":"https://avatars.githubusercontent.com/u/8947043?v=3","gravatar_id":"","url":"https://api.github.com/users/dayang","html_url":"https://github.com/dayang","followers_url":"https://api.github.com/users/dayang/followers","following_url":"https://api.github.com/users/dayang/following{/other_user}","gists_url":"https://api.github.com/users/dayang/gists{/gist_id}","starred_url":"https://api.github.com/users/dayang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dayang/subscriptions","organizations_url":"https://api.github.com/users/dayang/orgs","repos_url":"https://api.github.com/users/dayang/repos","events_url":"https://api.github.com/users/dayang/events{/privacy}","received_events_url":"https://api.github.com/users/dayang/received_events","type":"User","site_admin":false},"created_at":"2016-07-13T14:14:49Z","updated_at":"2016-07-13T14:14:49Z","body":"[AC] LeetCode 146 LRU Cache \r\n```js\r\n/**\r\n * @constructor\r\n */\r\nvar LRUCache = function(capacity) {\r\n    this.node = function(y,next,pre){\r\n        this.value = y;\r\n        this.next = next;\r\n        this.pre = pre;\r\n    }\r\n    this.capacity = capacity;\r\n    this.used = 0;\r\n    this.memery = {};\r\n    this.head = 0;\r\n    this.tail = 0;\r\n};\r\n\r\n/**\r\n * @param {number} key\r\n * @returns {number}\r\n */\r\nLRUCache.prototype.get = function(key) {\r\n    if(!this.memery[key])\r\n        return -1;\r\n    else{\r\n        if(key == this.head){\r\n            return this.memery[key].value;\r\n        }\r\n        if(key == this.tail){\r\n            this.tail = this.memery[this.tail].pre;\r\n        }\r\n        var temp = this.memery[key];\r\n        this.memery[temp.pre].next = temp.next;\r\n        this.memery[temp.next].pre = temp.pre;\r\n        this.memery[key].next = this.head;\r\n        this.memery[key].pre = this.memery[this.head].pre;\r\n        this.memery[this.memery[this.head].pre].next = key;\r\n        this.memery[this.head].pre = key;\r\n        this.head = key;\r\n        return temp.value;\r\n    }\r\n};\r\n\r\n/**\r\n * @param {number} key\r\n * @param {number} value\r\n * @returns {void}\r\n */\r\nLRUCache.prototype.set = function(key, value) {\r\n    if(!this.memery[key]){\r\n        if(this.used ===0){\r\n            this.head = this.tail = key;\r\n            this.memery[key] = new this.node(value,key,key);\r\n            this.used++;\r\n        }else if(this.used < this.capacity){ \r\n            this.memery[key] = new this.node(value,this.head,this.memery[this.head].pre);\r\n            this.memery[this.memery[this.head].pre].next = key;\r\n            this.memery[this.head].pre = key;\r\n            this.head = key;\r\n            this.used++;\r\n        }else{\r\n            this.memery[key] = new this.node(value,this.head,this.memery[this.head].pre);\r\n            this.memery[this.memery[this.head].pre].next = key;\r\n            this.memery[this.head].pre = key;\r\n            this.head = key;\r\n            var t = this.tail;\r\n            var pre = this.memery[t].pre;\r\n            this.memery[pre].next = this.memery[t].next;\r\n            this.memery[this.memery[t].next].pre = pre;\r\n            this.tail = pre;\r\n            delete this.memery[t];\r\n        }\r\n    }else{\r\n        if(key == this.head){\r\n            this.memery[key].value = value;\r\n            return;\r\n        }\r\n        if(key == this.tail){\r\n            this.tail = this.memery[this.tail].pre;\r\n        }\r\n        var temp = this.memery[key];\r\n        this.memery[key].value = value;\r\n        this.memery[temp.pre].next = temp.next;\r\n        this.memery[temp.next].pre = temp.pre;\r\n        this.memery[key].next = this.head;\r\n        this.memery[key].pre = this.memery[this.head].pre;\r\n        this.memery[this.memery[this.head].pre].next = key;\r\n        this.memery[this.head].pre = key;\r\n        this.head = key;\r\n    }\r\n};\r\n```"}}
{"actor":{"display_login":"dayang"}}