Home:ALL Converter>LeetCode: (26: Remove Duplicates from Sorted Array)

LeetCode: (26: Remove Duplicates from Sorted Array)

Ask Time:2022-10-07T22:44:21         Author:SHAHAD HUSSEIN

Json Formatter

I'm trying to solve a problem in LeetCode, which is (26. Remove Duplicates from Sorted Array), and it's saying that my code is incorrect, while it works perfectly in VS Code. Here is the code:

let nums = [1, 1, 2]
let k = 0
const removeDuplicates = nums => {
  nums = [...new Set(nums)]
  k = nums.length
  return k + '\n' + nums
}
console.log(removeDuplicates(nums))

Author:SHAHAD HUSSEIN,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73988903/leetcode-26-remove-duplicates-from-sorted-array
Asif Jalil :

var removeDuplicates = function(nums) {\n const set = new Set(nums);\n let i = 0;\n set.forEach(num => {\n nums[i] = num\n i++\n })\n\n return set.size;\n};\n",
2022-10-07T14:53:30
yy