Plus One - Leetcode 66 - Java

preview_player
Показать описание
Plus One - Leetcode 66 - Java

--------------------------------ABOUT--------------------------------
🧑🏻 My name is David and I am a software engineer at Meta. My passion is teaching software devs how to pass the grueling technical interviews to help them land their 6-figure dream tech job.

I have received 3 six-figure offers from Google, Meta, and Amazon.

🔬I provide content that will allow you to understand the thought process, pseudocode, time complexity, and code when approaching coding problems.

--------------------------------SOCIAL--------------------------------

💬 If you have any topic or questions you want me to cover, let me know in the comment section below ~ ฅʕ•ᴥ•`ʔ ฅʕ•ᴥ•`ʔ ฅʕ•ᴥ•`ʔ

#technicalinterview #techcareer #softwareengineer
Рекомендации по теме
Комментарии
Автор

this is no way easy one, ton of edge cases it should be a medium tagged one

シャム-dn
Автор

It is not a memory-optimized solution, nor the easiest logic. More optimised solution than this could be:

public int[] plusOne(int[] digits) {
int i = digits.length-1;
++digits[i];

while(digits[i] == 10) {
digits[i] = 0;
if(i > 0) {
digits[i-1] = ++digits[i-1];
} else {
int[] result = new int[digits.length + 1];
int arr[] = {1};
System.arraycopy(arr, 0, result, 0, 1);
System.arraycopy(digits, 0, result, 1, digits.length);
return result;
}
i--;
}
return digits;
}

prateekgupta
visit shbcf.ru