Skip to content

Instantly share code, notes, and snippets.

@evolvingsam
Created January 1, 2026 01:07
Show Gist options
  • Select an option

  • Save evolvingsam/e4a6f7c3cd8c179eb50cfa7d5124dcb7 to your computer and use it in GitHub Desktop.

Select an option

Save evolvingsam/e4a6f7c3cd8c179eb50cfa7d5124dcb7 to your computer and use it in GitHub Desktop.
Leetcode 2026 Day 1

Question

Approach

This is like a basic maths, I traversed the list and added the correct place value of subsequent digits to the previous ones, making the initial digit the 1 that should be added to the whole digits.

I got the place value by raising 10 to the power of (the length of the list − 1 − the index).

Then, I built a list from the resulting total digits and returned it.

Implementation

class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        start = 1
        n = len(digits)
        for i in range(n):
            start += digits[i] * (10 ** (n -i - 1))
        return [int(d) for d in str(start)]
day01

Complexities

  • Time: O(n) - traversing the list of digits
  • Space: O(n) - Building a list of the resulting digit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment