504_Base 7
Given an integer, return its base 7 string representation. The integer may be negative.
Example 1:
Example 2:
Solution:
Idea:
Use a sequence of module and division operations.
The integer mod base 7 will be in the number in last digit, the integer divide base 7 is the next integer to run
record the sign at the beginning
Time Complexity: where 7 is the base, n is the input number
Space Complexity: where 7 is the base, n is the input number
Code 1: iterative approach
Code 2: recursive approach
Last updated