[
greedy
]
BinarySearch 0328 123 Number Flip
Problem statement
https://binarysearch.com/problems/123-Number-Flip/
Solution
We need to flip to 3
the first digit we have, which is not equal to 3
.
Complexity
It is O(k)
for time and space, where k
is number of digits in n
.
Code
class Solution:
def solve(self, n):
s = str(n)
for i, elem in enumerate(s):
if s[i] != "3":
return int(s[:i] + "3" + s[i+1:])
return n