easy +5 pts

Strip Leading Zeros

Remove all leading zeros from a numeric string, but keep at least one digit.

Write a function `strip_leading_zeros(s)` that takes a string `s` representing a non-negative integer (so it contains only digits '0'-'9' and is non-empty) and returns a new string with all leading zeros removed. If the entire string consists of only zeros, return the single character '0'. The function must not use `int()` conversion or any built-in numeric casting; operate purely on strings. The input string can be up to 100,000 characters long, so your solution should be O(n).

Constraints

Input: a non-empty string consisting only of digits '0'-'9'. Length: 1 <= len(s) <= 100000. Output: a string with no leading zeros, but at least one digit. Do not use int(), float(), or any similar conversion. Complexity: linear time.

Example

>>> strip_leading_zeros('000123')
'123'
>>> strip_leading_zeros('0')
'0'
>>> strip_leading_zeros('000')
'0'
>>> strip_leading_zeros('007')
'7'
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Scan from the left until you find the first non-zero character.
If you reach the end without finding a non-zero, the answer is '0'.
Use string slicing to extract the remainder after the first non-zero.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.