// https://leetcode.com/problems/plus-one/submissions/
public class Solution {
public int[] PlusOne(int[] digits)
{
int[] toadd = new int[digits.Length];
toadd[toadd.Length - 1] = 1;
var numbers = new Stack<int>();
int inMemory = 0;
for (int i = digits.Length - 1; i >=0; i--)
{
int number = digits[i] + toadd[i] + inMemory;
if (number > 9)
{
string numberStr = number.ToString();
inMemory = numberStr[0] - '0';
numbers.Push(numberStr[1] - '0');
}
else
{
inMemory = 0;
numbers.Push(number);
}
}
if (inMemory > 0)
numbers.Push(inMemory);
int[] res = new int[numbers.Count];
int j = 0;
while (numbers.Count > 0)
{
var number = numbers.Pop();
res[j] = number;
j++;
}
return res;
}
}
-
MY PROJECTS
-
Recent Posts
- Algo. Java. Remove-duplicates-from-sorted-array
- Java.Hibernate.SimpleExample
- Java.Jdbc.SimpleExample
- SQL. Calc the sum with case, example
- Mullvad – free the internet :)
- Junit. Jupiter
- Java. SpringBoot Example how to work with dateTime in Specification
- Java.SpringBoot.PopularAnnotations
- SpringBoot. Exception Management
- Java.Hibernate.JoinTableAnnotation
- SpringBoot.Making our first starter and autoconfiguration
- Spring. Creating main annotation to start business logic
- Spring.Reading from properties file
- Spring.How to define spring version inside springBoot ?
- SpringBoot App inside Docker
- Kafka.FirstExperience
- Docker.MySql and Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
- Gradle.Tips
- Spring.AppConfig
- Leetcode.Best-time-to-buy-and-sell-stock
Categories
- Aptana
- Azure
- C#
- DataSnap
- DBExpress
- Delphi
- Delphi и сети
- Delphi. Язык программирования
- ExtJS
- FastReport
- FireDAC
- FireMonkey
- GIT
- ICS
- IDE
- IIS
- Indy
- InnoSetup
- javascript
- jQuery
- JSON
- LiveBindings
- MSHTML
- MySQL
- PHP
- REST
- Ribbons
- SMS
- SQL инструкции
- SVN
- TRichView
- UniGui
- WebBroker
- WinAPI
- Windows
- Алгоритмы
- Без рубрики
- Деревья
- Ищу ответ
- Компонентостроение
- Мои компоненты
- Начальный уровень
- Обработка исключений
- Парсинг
- Потоки(Threads)
- Регулярные выражения
- Тестирование приложений