Problem statement

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

Solution

Just traverse string and evaluate answer.

Complexity

It is O(n) for time, where n = len(s) and O(1) for space.

Code

class Solution:
    def solve(self, s):
        ans = 0
        for i in s:
            ans = ans * 3 + int(i)
        return ans