Plus One Javascript Leetcode | For Loop Javascript | Algorithm explained

preview_player
Показать описание
🔴 Question Link -

✅Connect with me

🔴 Question with Example
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

You may assume the integer does not contain any leading zero, except the number 0 itself.

Example 1:

Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Рекомендации по теме
Комментарии
Автор

Hi Persistent Programmer! First of all, thank you so much for this video. I find your algo very helpful and efficient. You are great at explaining this step by step!

I do have a quick question. When I first encountered this problem on Leetcode, this is what I wrote -
var plusOne = function(digits) {
let numbered = Number(digits.join(''))+1
return
};


This seems to work on digits up to like 15 or 16 numbers but above that, it doesn't seem to work. Would you know happen to know why?

Thank you!

wonjaesung
Автор

That’s great, can you pls recommend some js channels for beginners?

ol
Автор

loving the video, thanks for making these.

redgreenbluehex
Автор

I like the way you made the presentation. Do you mind sharing the app or tool to make such kind of presentation?

anildangol
Автор

Thank you for sharing this! I am a little confused with .unshift() I thought unshift adds to the front of the array but when I run the test case for example [1, 2, 9] the output becomes [1, 3, 0] which is technically correct but from my interpretation of unshift it should appear [2, 2, 0].

Could you clarify why this is happening?
My understanding would be that since we are starting at the back of the array the "2" would be the front and that is why we are adding + 1 to it.
If that is the case then it makes perfect sense.

RemsterHD
welcome to shbcf.ru