Day - 38
Assalamu alaykum, everyone! How are you dears?
I am posting articles containing my 100 days of coding challenge. During this period I learned many things about the value of time. Because I can remember the 1st day of my challenge as "yesterday". But, it is the 38th day of that coding challenge. Time does not wait for us. Try to do your best in your spare time. Those actions should positively affect your future life, else get rid of them! Because every second of our life is valuable. What do you think? Is it true?
If your answer is yes, then start doing good deeds from today! For example, start learning something like programming or design! Do not stop anywhere!
Sorry for that kind of words! These words were out of topic, but I wanted to tell you by this post!
Ok, let's continue our challenge.
/*
* @param {number[]} nums
* @return {number[]}
*/
var findErrorNums = function (nums) {
let sum = (nums.length * (nums.length + 1)) / 2,
dup = 0,
arr = Array(nums.length).fill(0);
for (let i = 0; i < nums.length; i++) {
if (arr[nums[i] - 1] === nums[i]) dup = nums[i];
else {
arr[nums[i] - 1] = nums[i];
sum -= nums[i];
}
}
return [dup, sum];
};
That's all. Thanks for your attention! I love your support dear my followers! If you like the post, share it with your friends as well!