150 najlepszych wywiadówŁatwe

Plus jeden

Szczegółowy przewodnik i implementacja Python dla problemu „Plus One”.

Oświadczenie o problemie

Łatwe

Otrzymujesz dużą liczbę całkowitą reprezentowaną jako tablica liczb całkowitych cyfr, gdzie każda cyfra [i] jest i-tą cyfrą liczby całkowitej. Cyfry są uporządkowane od najbardziej znaczącej do najmniej znaczącej, w kolejności od lewej do prawej. Duża liczba całkowita nie zawiera żadnych wiodących zer.

Zwiększ dużą liczbę całkowitą o jeden i zwróć wynikową tablicę cyfr.

Zaimplementuj funkcję plusOne(digits: list) -> list.

Ograniczenia
  • 1 <= digits.length <= 100
  • 0 <= digits[i] <= 9
  • digits does not contain any leading 0's

Przykłady

Example 1
Input
[1,2,3]
Output
[1,2,4]
Explanation

The array represents the integer 123. Incrementing by one gives 124.

Example 2
Input
[4,3,2,1]
Output
[4,3,2,2]
Explanation

The array represents the integer 4321. Incrementing by one gives 4322.

Example 3
Input
[9]
Output
[1,0]
Explanation

The array represents the integer 9. Incrementing by one gives 10, which is [1,0].

Need a Hint?
Rozważ użycie struktur danych specyficznych dla matematyki i geometrii, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.