less than 1 minute read

Given a string s representing a number in base 3 (consisting only of 0, 1, or 2), return its decimal integer equivalent. This should be implemented directly without using a built-in function.

https://binarysearch.com/problems/Base-3-to-Integer

Examples

Example 1

Input

  • s = 10

Output

  • answer = 3

Example 2

Input

  • s = 21

Output

  • answer = 7

Solution

Leave a comment