payload: {"action":"created","issue":{"url":"https://api.github.com/repos/weijiyang/leetcode/issues/27","repository_url":"https://api.github.com/repos/weijiyang/leetcode","labels_url":"https://api.github.com/repos/weijiyang/leetcode/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/weijiyang/leetcode/issues/27/comments","events_url":"https://api.github.com/repos/weijiyang/leetcode/issues/27/events","html_url":"https://github.com/weijiyang/leetcode/issues/27","id":516841941,"node_id":"MDU6SXNzdWU1MTY4NDE5NDE=","number":27,"title":"移除元素","user":{"login":"weijiyang","id":23150533,"node_id":"MDQ6VXNlcjIzMTUwNTMz","avatar_url":"https://avatars2.githubusercontent.com/u/23150533?v=4","gravatar_id":"","url":"https://api.github.com/users/weijiyang","html_url":"https://github.com/weijiyang","followers_url":"https://api.github.com/users/weijiyang/followers","following_url":"https://api.github.com/users/weijiyang/following{/other_user}","gists_url":"https://api.github.com/users/weijiyang/gists{/gist_id}","starred_url":"https://api.github.com/users/weijiyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weijiyang/subscriptions","organizations_url":"https://api.github.com/users/weijiyang/orgs","repos_url":"https://api.github.com/users/weijiyang/repos","events_url":"https://api.github.com/users/weijiyang/events{/privacy}","received_events_url":"https://api.github.com/users/weijiyang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-11-03T15:10:27Z","updated_at":"2019-11-04T01:09:40Z","closed_at":null,"author_association":"OWNER","body":"给定一个数组 nums 和一个值 val，你需要原地移除所有数值等于 val 的元素，返回移除后数组的新长度。\r\n\r\n不要使用额外的数组空间，你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。\r\n\r\n元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。\r\n\r\n示例 1:\r\n\r\n给定 nums = [3,2,2,3], val = 3,\r\n\r\n函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。\r\n\r\n你不需要考虑数组中超出新长度后面的元素。\r\n示例 2:\r\n\r\n给定 nums = [0,1,2,2,3,0,4,2], val = 2,\r\n\r\n函数应该返回新的长度 5, 并且 nums 中的前五个元素为 0, 1, 3, 0, 4。\r\n\r\n注意这五个元素可为任意顺序。\r\n\r\n你不需要考虑数组中超出新长度后面的元素。\r\n说明:\r\n\r\n为什么返回数值是整数，但输出的答案是数组呢?\r\n\r\n请注意，输入数组是以“引用”方式传递的，这意味着在函数里修改输入数组对于调用者是可见的。\r\n\r\n你可以想象内部操作如下:\r\n\r\n// nums 是以“引用”方式传递的。也就是说，不对实参作任何拷贝\r\nint len = removeElement(nums, val);\r\n\r\n// 在函数里修改输入数组对于调用者是可见的。\r\n// 根据你的函数返回的长度, 它会打印出数组中该长度范围内的所有元素。\r\nfor (int i = 0; i < len; i++) {\r\n    print(nums[i]);\r\n}\r\n\r\n来源：力扣（LeetCode）\r\n链接：https://leetcode-cn.com/problems/remove-element\r\n著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。"},"comment":{"url":"https://api.github.com/repos/weijiyang/leetcode/issues/comments/549199599","html_url":"https://github.com/weijiyang/leetcode/issues/27#issuecomment-549199599","issue_url":"https://api.github.com/repos/weijiyang/leetcode/issues/27","id":549199599,"node_id":"MDEyOklzc3VlQ29tbWVudDU0OTE5OTU5OQ==","user":{"login":"weijiyang","id":23150533,"node_id":"MDQ6VXNlcjIzMTUwNTMz","avatar_url":"https://avatars2.githubusercontent.com/u/23150533?v=4","gravatar_id":"","url":"https://api.github.com/users/weijiyang","html_url":"https://github.com/weijiyang","followers_url":"https://api.github.com/users/weijiyang/followers","following_url":"https://api.github.com/users/weijiyang/following{/other_user}","gists_url":"https://api.github.com/users/weijiyang/gists{/gist_id}","starred_url":"https://api.github.com/users/weijiyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weijiyang/subscriptions","organizations_url":"https://api.github.com/users/weijiyang/orgs","repos_url":"https://api.github.com/users/weijiyang/repos","events_url":"https://api.github.com/users/weijiyang/events{/privacy}","received_events_url":"https://api.github.com/users/weijiyang/received_events","type":"User","site_admin":false},"created_at":"2019-11-04T01:09:40Z","updated_at":"2019-11-04T01:09:40Z","author_association":"OWNER","body":"下面这个换了一种思路实现\r\n```\r\n/**\r\n * @param {number[]} nums\r\n * @param {number} val\r\n * @return {number}\r\n */\r\nvar removeElement = function(nums, val) {\r\n    let ans = 0\r\n    for(let i =0 ; i<nums.length; i++){\r\n        if(nums[i] !== val){\r\n            nums[ans] = nums[i]\r\n            ans++\r\n        }\r\n    }\r\n    return ans\r\n};\r\n```\r\n\r\n"}}
other: {"actor":{"display_login":"weijiyang"}}